j2lstaples Posted August 4, 2023 Posted August 4, 2023 Hello everyone, Another productive day and a couple days really coding in AutoLISP. I'm here to share with you an automated annotation block placement that I wrote with the help of chatGPT (for helper functions), referencing all the experts in this forum and some of my wit in trying to optimize it. Here we have an ent (which is an entity name) that we want to put callup bubbles on and we're using a multileader-ish block called RSBALLOON + LEADER, which I have in my library. This is basically a block that has a leader on it that is modified using LM:setdynpropvalue. We actually just use ssget as a filtering tool used in boundscan, which is just a ssget crossing selection knowing the area you specify. I've learned a few lessons when I coded this. If you set this iteratively, this will have issues because the 'point' will drift. LISP fumbles where to place your blocks. You can "regen" everytime you place a block but that costs time. I've solved this by using a separate function that zooms into a viewport per entity that I'm doing a calculation on. Mind you, this block placement task usually takes a couple of hours to do manually because you want it to look pretty and visible with no obstructions. Now it only takes under a minute. I haven't really cleaned up the code but I was so excited in sharing this accomplishment. (defun MA:susp-callup-insert (ent radlist anglelist / entloc spc point blkobj) ; (setq radList (list 600 700 800 900 1000 1100 1200 1300 1400)) ; (setq anglelist (list 45 15 75 315 345 285 135 165 105 225 195 255 30 60 330 300 150 120 210 240 35 55 25 65 5 85 325 305 335 295 355 275 45 125 ....)) (setq entloc (cdr (assoc 10 (entget ent)))) (setq entloc (subst 0.0 (caddr entloc) entloc)) (setq spc (vlax-get-property (LM:acdoc) (if (= 1 (getvar 'cvport)) 'paperspace 'modelspace ) ) ) (setq blkname "RSBALLOON + LEADER") (setq blkobj nil exitLoop1 nil exitLoop2 nil idxrad 0 rad (nth 0 radlist) ) ;(start-timer) (while (and (not exitLoop1) rad) (setq idxang 0 exitLoop2 nil ang (nth 0 anglelist) ) (while (and (not exitLoop2) ang) (progn (setq angrad (deg2rad ang)) (setq point (mapcar '+ entloc (list (* rad (cos angrad)) (* rad (sin angrad)) 0.0 ) ) ) (if (not (boundScan point 200)) (progn ; (setq blkobj (vla-insertblock ; spc ; (vlax-3D-point point) ; blkname ; 50 ; 50 ; 50 ; 0.0 ; ) ; ) ;(command "UCS" "W") (command "_.insert" blkname point 50 50 0.0) ;(command "regen" ) (setq blkobj (vlax-ename->vla-object (entlast))) (LM:setdynpropvalue blkobj "Distance1" rad) (LM:setdynpropvalue blkobj "Angle1" (+ pi angrad)) (LM:vl-setattributevalue blkobj "ITEM_NO" (LM:vl-getattributevalue (vlax-ename->vla-object ent) "ITEM_NO" ) ) ;(command "_regen") (setq exitLoop2 T exitLoop1 T ) ) ; exit progn ) ; end if (setq ang (nth (setq idxang (+ 1 idxang)) anglelist)) ) ) (setq rad (nth (setq idxrad (+ 1 idxrad)) radList)) ) ;(end-timer) ; (princ "Let's goooooooooo!!!!\n") ; (princ) ) Quote
BIGAL Posted August 5, 2023 Posted August 5, 2023 Try changing to this (command "-_.insert" blkname point 50 50 0.0) Quote
mhupp Posted August 5, 2023 Posted August 5, 2023 (edited) 9 hours ago, j2lstaples said: I've learned a few lessons when I coded this. If you set this iteratively, this will have issues because the 'point' will drift. LISP fumbles where to place your blocks. You can "regen" everytime you place a block but that costs time. I've solved this by using a separate function that zooms into a viewport per entity that I'm doing a calculation on. Point doesn't drift per say it snaps to close entities depending on zoom level. When using points with command function either turn off snaps or put "_non" before the point call. (command "_.insert" blkname "_non" point 50 50 0.0) -Edit why the loops? Also you can get and set property values with one easy function. no need for sub functions. (setpropertyvalue blkobj "Distance1" rad) (setpropertyvalue blkobj "Angle1" (+ pi angrad)) (setpropertyvalue blkobj "ITEM_NO" (getpropertyvalue ent "ITEM_NO")) the help page only says entity name but i think they work with vla-objects as well. https://help.autodesk.com/view/ACD/2023/ENU/?guid=GUID-8F32FD8C-D81A-4DCA-B455-9D560CF17246 https://help.autodesk.com/view/ACD/2023/ENU/?guid=GUID-8E5913FC-09ED-4C70-AFB7-2431C062E899 Edited August 5, 2023 by mhupp 1 Quote
j2lstaples Posted August 6, 2023 Author Posted August 6, 2023 22 hours ago, mhupp said: Point doesn't drift per say it snaps to close entities depending on zoom level. When using points with command function either turn off snaps or put "_non" before the point call. (command "_.insert" blkname "_non" point 50 50 0.0) -Edit why the loops? WOW!! This was so informative. The "non" before the point call is INCREDIBLE. It just WORKS. I didn't need to zoom in to individual blocks to make it accurate. It made it even more incredible that when I run my CALLUP code, it just flies and it's so satisfying to watch. I love your mind @mhupp. It used to take 40 seconds for 100 blocks to annotate, now I can watch it do it in real time and be amused for a few seconds. 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.