
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all!
I have written a lisp that in theory should comb through my drawing, select all my dynamic blocks, check their width attributes, and then give me the total lengths of each different width value. (example: "Order 4 units of 3" wide wireway, Order 2 units of 2" wide wireway, etc....)
I've only been learning lisp for a couple weeks, so my knowledge level does not support my level of code ambition.
If anyone is willing to take the time to help point out what i'm doing that is wrong, or where i can make improvements, or any hints or tips, I would be very thankful! 🙂
Here are some additional details that may be helpful:
There is only one dynamic block on my drawing, its called DynPan (for dynamic panduit). (Though many of these blocks exist on the drawing)
It has a "Width" attribute and "Length" attribute.
There are only 6 allowed options for the width attribute. This is the "realwidth" called in my code.
These are 1.25, 1.75, 2.25, 3.25, 4.25, & 6.25.
The manufacture lists these as 0.25" smaller than the actual width. (so 1.25 is actually called 1", 1.75 is actually called 2", and so on)
;;;WirewayCalc_3.0 Written by Bw 11-08-2021
(vl-load-com)
(defun c:PanCalc (/ width realwidth total selectionset intger selectionsetname obj n i)
; ❤️ Lee Mac the Man, the Myth, the Legend <3
(defun LM:getdynpropvalue ( blk prp )
(setq prp (strcase prp))
(vl-some '(lambda ( x ) (if (= prp (strcase (vla-get-propertyname x))) (vlax-get x 'value)))
(vlax-invoke blk 'getdynamicblockproperties)
)
) ; Lee Mac never ends. ;)
(setq n 0)
(setq i 0)
(setq realwidth '(1.25 1.75 2.25 3.25 4.25 6.25))
(setq total '(0.0 0.0 0.0 0.0 0.0 0.0))
(setq units '(0.0 0.0 0.0 0.0 0.0 0.0))
(if (setq selectionset
(ssget "x" '((2 . "`*U*"))
) ;end creating the selection set
)
(progn
(repeat 6
(repeat (setq intger (sslength selectionset))
(setq selectionsetname
(ssname selectionset
(setq intger (1- intger))
)
obj (vlax-ename->vla-object selectionsetname)
) ;end setqs
(set (nth n total) (+ (nth n total)
(cond
(
(= (LM:getdynpropvalue obj "Width") (nth n realwidth))
(LM:getdynpropvalue obj "Length")
)
(0)
) ;end conditional
) ;end totaling the lengths
) ;end set
(set (nth n units) (1+ (fix (* 1.25 (/ (/ (nth n total) 12) 6)))))
(setq n (1+ n))
) ;end second repeat
) ; end first repeat
(repeat 6
(setq width (- (nth i realwidth) 0.25))
(princ ( strcat "\nYou'll want to order the following number of 6 foot long by " (rtos width 2) " units of wireway: ---> "(rtos (nth i units) 2)))
(princ )
) ; end repeat
) ;end progn
(princ)
) ;end if
(princ)
) ;end function
Solved! Go to Solution.