solid insertion point mystery
This code generates 4 solids in an arrangement like a 4 sided box, with the sides full height, and the top and bottom set in between.
-If I run this in a new drawing (either 2023 or 2024) it works correctly as expected.
-If I run it again , the new solids are generated in exactly the same place - correct and as expected again.
-If I delete those solids and run it again, the result now has the top sitting above the top of the sides by the thickness of material, which is wrong. All subsequent runs of the lisp will be wrong.
-If I start a new drawing and run the lisp, it will be correct again.
The insertion points of the top are right in all cases, but the solid is only in the right place for the first run.
I can't see where it's going wrong;
(defun c:CreateCabinetParts ()
(setvar "CMDECHO" 0)
(princ "\nStarting cabinet creation...")
(if (null (tblsearch "LAYER" "BoxParts"))
(progn
(command "._layer" "m" "BoxParts" "")
(princ "\nCreated BoxParts layer.")
)
(progn
(command "._layer" "s" "BoxParts" "")
(princ "\nSet current layer to BoxParts.")
)
)
(defun create-box (x y z width depth height)
(princ (strcat "\nDebug - Before box creation:"))
(princ (strcat "\n X: " (rtos x) ", Y: " (rtos y) ", Z: " (rtos z)))
(princ (strcat "\n Width: " (rtos width) ", Depth: " (rtos depth) ", Height: " (rtos height)))
(princ (strcat "\n Current OSMODE: " (rtos (getvar "OSMODE"))))
(princ (strcat "\n Current INSBASE: " (vl-princ-to-string (getvar "INSBASE"))))
(command "._box"
(list x y z)
"l" width depth height
)
(if (= (type (entlast)) 'ENAME)
(progn
(princ "\nBox created successfully.")
(setq last-ent (entlast))
(princ (strcat "\nDebug - After box creation:"))
(princ (strcat "\n Entity type: " (cdr (assoc 0 (entget last-ent)))))
(princ (strcat "\n Insertion point: " (vl-princ-to-string (cdr (assoc 10 (entget last-ent))))))
)
(princ "\nError: Failed to create box.")
)
)
(princ "\n\nCreating Cabinet 1 (Base Cab)")
(princ (strcat "\nDimensions: " (rtos 40) "x" (rtos 10) "x" (rtos 25)))
(setq cabinet-width 40)
(setq cabinet-depth 10)
(setq cabinet-height 25)
(setq thickness 0.75)
; Left Side
(create-box 0.0 0.0 0.0 thickness cabinet-depth cabinet-height)
; Right Side
(create-box (- cabinet-width thickness) 0.0 0.0 thickness cabinet-depth cabinet-height)
; Bottom
(create-box thickness 0.0 0.0 (- cabinet-width (* 2 thickness)) cabinet-depth thickness)
; Top
(create-box thickness 0.0 (- cabinet-height thickness) (- cabinet-width (* 2 thickness)) cabinet-depth thickness)
(princ "\nAll parts for this cabinet should now be created.")
(setvar "CMDECHO" 1)
(princ "\nCabinet creation completed.")
(princ)
)
(princ "\nType 'CreateCabinetParts' to create cabinet structures.")
(princ)
Comments
-
Maybe your entity snap settings are interfering.
you can turn them off in the beginning of the script
(setq osnapsetting (getvar "Osmode"))
(setvar "Osmode" 0)and turn them back to previous at the end
(setvar "Osmode" osnapsetting)
0 -
I think that was it - thanks!
0 -
Just a comment a front end for something similar. These are pretty easy to make.
0