Jump to content

ActiveX Server returned the error: unknown name: Move


pttr

Recommended Posts

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)
)

 

Link to comment
Share on other sites

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 by EnM4st3r
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Steven P
Link to comment
Share on other sites

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.
image.thumb.png.e12271446404a0d8e1835a819ab1ef2b.png

 

 

All i really want is to cahnge Position X of this blockdefinition


 

Edited by pttr
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)
)

 

  • Thanks 1
Link to comment
Share on other sites

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! :)

  • Like 1
Link to comment
Share on other sites

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)
)

 

  • Like 1
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...