pttr Posted February 20 Posted February 20 Hi, I´m trying to move some blocks but i get ActiveX error. ActiveX Server returned the error: unknown name: Move Here is the code, but feels like i need to reinstall Cad? (defun c:MoveBlocks () (setq target-point '(300.0 5.25 0.0)) (setq block-name "RegionserviceUTR") (vl-load-com) (defun move-blocks (block-name target-point) (vlax-for block (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) (if (equal block-name (vla-get-Name block)) (vla-move block target-point) ) ) ) (move-blocks block-name target-point) (princ "Blocks moved successfully.") (princ) ) Quote
EnM4st3r Posted February 20 Posted February 20 (edited) 1. you cannot move a Blockdefinitionn only a BlockReference. The method your using gives you the Blockdefinition. 2. you need 3 Arguments for the vla-move method: (vla-Move Object<vla-object> Point1<variant:xyz> Point2<variant:xyz>) 3. your pointlist has to be in variant format so use vlax-3d-point to convert your point list to a variant Edited February 20 by EnM4st3r Quote
pttr Posted February 20 Author Posted February 20 23 minutes ago, EnM4st3r said: 1. you cannot move a Blockdefinitionn only a BlockReference. The method your using gives you the Blockdefinition. 2. you need 3 Arguments for the vla-move method: (vla-Move Object<vla-object> Point1<variant:xyz> Point2<variant:xyz>) 3. your pointlist has to be in variant format so use vlax-3d-point to convert your point list to a variant That´s unfortunate. I utilized the block definition to modify attributes, which was convenient when I needed to alter every instance of the block. But... I also need to move each block. Quote
Steven P Posted February 20 Posted February 20 (edited) It looks like you are trying to move all the blocks with the block definition name RegionserviceUTR to a single point? I guess this is only a part of what you are trying to do. Try this way (defun c:MoveBlocks ( / target-point block-name) (setq target-point '(300.0 5.25 0.0)) ;;Point to move to (setq block-name "RegionserviceUTR") ;;Block Name to move (MoveBlock target-point block-name) ;;Run the nmove bock LISP with the above name and point (princ "\nBlocks Moved Successfully") ;;Report success (princ) ;;Exit quietly ) (defun MoveBlock (target-point block-name / BlockSS acount) (setq BlockSS (ssget "_X" (list '(0 . "INSERT")(cons 2 block-name)))) ;;Select all blocks with the specified name ;;Can alter the ssget filter as required - resources online - doesn't 'need' the '0' if you are specifying the '2' in nearly all cases. (setq acount 0) ;; Just a counter (while (< acount (sslength BlockSS)) ;; Loop through the selected blocks (entmod (subst (cons 10 target-point) ;; Substitute insert point: New insert point (assoc 10 (entget (ssname BlockSS acount))) ;; Existing insert point (entget(ssname BlockSS acount)) ;; Entity to update )) (setq acount (+ acount 1)) ;; Count a little bit more ) ; end while ;; End Loop ) Edited February 20 by Steven P Quote
pttr Posted February 20 Author Posted February 20 (edited) 12 minutes ago, Steven P said: It looks like you are trying to move all the blocks with the block definition name RegionserviceUTR to a single point? I guess this is only a part of what you are trying to do. Try this way (defun c:MoveBlocks ( / target-point block-name) (setq target-point '(300.0 5.25 0.0)) ;;Point to move to (setq block-name "RegionserviceUTR") ;;Block Name to move (MoveBlock target-point block-name) ;;Run the nmove bock LISP with the above name and point (princ "\nBlocks Moved Successfully") ;;Report success (princ) ;;Exit quietly ) (defun MoveBlock (target-point block-name / BlockSS acount) (setq BlockSS (ssget "_X" (list '(0 . "INSERT")(cons 2 block-name)))) ;;Select all blocks with the specified name (setq acount 0) ;; Just a counter (while (< acount (sslength BlockSS)) ;; Loop through the selected blocks (entmod (subst (cons 10 target-point) ;; Substitute insert point: New insert point (assoc 10 (entget (ssname BlockSS acount))) ;; Existing insert point (entget(ssname BlockSS acount)) ;; Entity to update )) (setq acount (+ acount 1)) ;; Count a little bit more ) ; end while ;; End Loop ) Yes exactly! That creates a diffrent problem... Im not sure how to explain it but all instances of the block moves. But inside the block there are other textnotes that (also are the attributes of the block) that wont move with the rest. The text that is marked wont move and the text that is not marked moves. All i really want is to cahnge Position X of this blockdefinition Edited February 20 by pttr Quote
Steven P Posted February 20 Posted February 20 Post a sample drawing, it should be reasonably easy but could be a couple of things - so post a sample if you can with the example block in it Quote
pttr Posted February 20 Author Posted February 20 Thank you! You will find the block in layouts Drawing2.dwg Quote
Steven P Posted February 20 Posted February 20 Looking at the block, probably AttSync will work. Sometimes this won't work if you have changed the attributes in a block in the Enhanced Attribute Editor, AttSync will reset them to the default, so try below. For example, Sometimes with title blocks if the freetexts - drawing title or description can extend out of the area assigned and you change the width factor perhaps - attsync will reset that (as a example) (defun c:MoveBlocks ( / target-point block-name) (setq target-point '(300.0 5.25 0.0)) ;;Point to move to (setq block-name "RegionserviceUTR") ;;Block Name to move (MoveBlock target-point block-name) ) (defun MoveBlock (target-point block-name / BlockSS acount) (setq BlockSS (ssget "_X" (list '(0 . "INSERT")(cons 2 block-name)))) (setq acount 0) (while (< acount (sslength BlockSS)) (entmod (subst (cons 10 target-point) (assoc 10 (entget (ssname BlockSS acount))) (entget (ssname BlockSS acount)) )) (setq acount (+ acount 1)) ) ; end while (command "attsync" "N" block-name) ) 1 Quote
pttr Posted February 20 Author Posted February 20 27 minutes ago, Steven P said: Looking at the block, probably AttSync will work. Sometimes this won't work if you have changed the attributes in a block in the Enhanced Attribute Editor, AttSync will reset them to the default, so try below. For example, Sometimes with title blocks if the freetexts - drawing title or description can extend out of the area assigned and you change the width factor perhaps - attsync will reset that (as a example) (defun c:MoveBlocks ( / target-point block-name) (setq target-point '(300.0 5.25 0.0)) ;;Point to move to (setq block-name "RegionserviceUTR") ;;Block Name to move (MoveBlock target-point block-name) ) (defun MoveBlock (target-point block-name / BlockSS acount) (setq BlockSS (ssget "_X" (list '(0 . "INSERT")(cons 2 block-name)))) (setq acount 0) (while (< acount (sslength BlockSS)) (entmod (subst (cons 10 target-point) (assoc 10 (entget (ssname BlockSS acount))) (entget (ssname BlockSS acount)) )) (setq acount (+ acount 1)) ) ; end while (command "attsync" "N" block-name) ) Oh that worked perfect, many thanks! 1 Quote
Steven P Posted February 20 Posted February 20 and for completion, this uses VLA- functions, you were half way there earlier - no attsync required (defun c:MoveBlocks ( / target-point block-name) (setq target-point '(300.0 5.25 0.0)) ;;Point to move to (setq block-name "RegionserviceUTR") ;;Block Name to move (MoveBlock target-point block-name) ) (defun MoveBlock (target-point block-name / BlockSS acount) (setq BlockSS (ssget "_X" (list '(0 . "INSERT")(cons 2 block-name)))) (setq acount 0) (while (< acount (sslength BlockSS)) (setq Pt1 (vlax-3d-point (cdr (assoc 10 (entget (ssname BlockSS acount) )))) ) (setq Pt2 (vlax-3d-point target-point) ) (vla-move (vlax-ename->vla-object (ssname BlockSS acount)) Pt1 Pt2) (setq acount (+ acount 1)) ) ; end while (princ) ) 1 Quote
pttr Posted February 21 Author Posted February 21 Oh okay, now I get it. Thats what I was trying to do! Thanks! 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.