HOW TO BLOCK SELECT AND MOVE COORDINATES IN MULTIPLE DRAWINGS IN AUTOLISP

HOW TO BLOCK SELECT AND MOVE COORDINATES IN MULTIPLE DRAWINGS IN AUTOLISP

Anonymous
Not applicable
2,291 Views
9 Replies
Message 1 of 10

HOW TO BLOCK SELECT AND MOVE COORDINATES IN MULTIPLE DRAWINGS IN AUTOLISP

Anonymous
Not applicable

HELLO GOOD MORNING, I AM NEW TO THIS AUTOLISP AND I WOULD LIKE TO SEE IF YOU COULD HELP ME CONFIGURE A ROUTINE TO MODIFY ABOUT 300 DRAWINGS .DWG
MY DIFFICULTY IS THAT IN THE PROJECT WE HAVE THE PLANE DATA DEPASSED FROM ITS CORRECT POSITION, THE NAME OF THE BLOCK IS FOUND IN THE LAYOUT AND IS CALLED "PIE_DE_PLANO_DATOS_AUDINGMEX" THE ONLY THING I WANT TO MOVE THE POSITION CORDINATE (y) 6.85 A 6.35   PERFORM THAT HOMEWORK IN THE 300 DRAWINGS. I HOPE YOU CAN HELP ME.

 

I ATTACH YOU THE DWG FILE.

 

BLOCK NAME "PIE_DE_PLANO_DATOS_AUDINGMEX"

 

COORDINATES IN THE LAYOUT
POSITION X 4.0666
POSITION Y 6.85
POSITION Z 0.00

 

I WANT TO PASS THE POSITION "Y" TO POSITION AND 6.35

0 Likes
Accepted solutions (2)
2,292 Views
9 Replies
Replies (9)
Message 2 of 10

ronjonp
Mentor
Mentor
Accepted solution

You need to go download some code and load it before you run this.

Definitely test it out on some dummy drawings first! 🍻

 

(defun c:foo (/ _moveit)
  (defun _moveit (doc)
    (vlax-for o	(vla-get-blocks doc)
      (vlax-for	b o
	(and (= "AcDbBlockReference" (vla-get-objectname b))
	     (= "PIE_DE_PLANO_DATOS_AUDINGMEX" (strcase (vla-get-effectivename b)))
	     (vl-catch-all-apply 'vlax-put (list b 'insertionpoint '(4.066 6.35 0.0)))
	)
      )
    )
  )
  (if (= 'usubr (type lm:odbx))
    (lm:odbx '_moveit nil t)
    (alert "Load the code here! http://www.lee-mac.com/odbxbase.html")
  )
  (princ)
)

 

 

0 Likes
Message 3 of 10

Anonymous
Not applicable

Hi (Ronjonp) Very good Lisp, but it did not work, I did not make any change of position.
make few modifications to your programming and it is perfect !!!
I would like to know what these codes mean, or what functions the calls make?

 

 

(vlax-for o	(vla-get-blocks doc)
      (vlax-for	b o
	(and (= "AcDbBlockReference" (vla-get-objectname b))

 

 

the final code was this way

 

 

(defun c:foo ()
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
    (vlax-for blk (vla-get-blocks doc)
      (vlax-for	b blk
	(and (= "AcDbBlockReference" (vla-get-objectname b))
	     (= "PIE_DE_PLANO_DATOS_AUDINGMEX" (strcase (vla-get-effectivename b)))
	     (vl-catch-all-apply 'vlax-put (list b 'insertionpoint '(4.066 6.35 0.0)))
	)
      )
    )
  )
  (if (= 'usubr (type lm:odbx))
    (lm:odbx '_moveit nil t)
  (princ)
)

 

thank you very much for your great help !!!!
I leave the final code that worked for me and which I will use with pro script.

 

 

0 Likes
Message 4 of 10

ronjonp
Mentor
Mentor
Accepted solution

If you use the code as it was designed you can process all 300 drawings very fast.

Why the blockname change from 'BLOCK NAME "PIE_DE_PLANO_DATOS_AUDINGMEX" to "01" ? That would definitely make it not work if it was looking at the wrong block.😉 

 

The change you made works on the current drawing and the code provided will do a whole directory .. you have to load the code I linked to first though!

0 Likes
Message 5 of 10

Anonymous
Not applicable

I did not know how to occupy the code, or how to start it to modify the 300 files, I did not know how to start it so that it would make me a complete directory.

Change the name of the block only for test reasons, but it is still "PIE_DE_PLANO_DATOS_AUDINGMEX".

Thank you very much for everything, it was a great help.

0 Likes
Message 6 of 10

ronjonp
Mentor
Mentor

Glad to help 🍻

0 Likes
Message 7 of 10

higarcia4SPJ6
Explorer
Explorer

hello friend, you helped me with this script before, currently I need a change in the code.
What I need is for the script to select (several blocks with different names) and move them to different coordinates. This script is perfect but you could help me to update it just by modifying it so that the selection of the names of the blocks is through the command line as well as the insertion of the coordinates.
This would help me since I plan to make the updates to more than 5000 blocks through excel.

0 Likes
Message 8 of 10

ronjonp
Mentor
Mentor

@higarcia4SPJ6 

;; Change this
(= "PIE_DE_PLANO_DATOS_AUDINGMEX" (strcase (vla-get-effectivename b)))
;; To this ( USE UPPERCASE )
(wcmatch (strcase (vla-get-effectivename b)) "BLOCK1,BLOCK2,BLOCK3")
0 Likes
Message 9 of 10

higarcia4SPJ6
Explorer
Explorer

Thanks, I was reviewing the code with chatgpt, and it made some modifications, I see them fine, except that the code only recognizes the first block, it can't read the others, what do you think is going wrong?

Your advice will be very helpful.

Thank you

 

(defun c:coord ()
(setq doc (vla-get-activedocument (vlax-get-acad-object)))
(setq blockName (getstring "\nEnter block name: "))
(setq newInsertionPoint (getpoint "\nEnter new insertion point: "))

(vlax-for blk (vla-get-blocks doc)
(vlax-for b blk
(when (and (= "AcDbBlockReference" (vla-get-objectname b))
(= blockName (strcase (vla-get-effectivename b))))
(vla-put-insertionpoint b (vlax-3d-point (list (car newInsertionPoint) (cadr newInsertionPoint) (caddr newInsertionPoint))))
)
)
)

(if (= 'usubr (type lm:odbx))
(lm:odbx '_moveit nil t)
)
)

0 Likes
Message 10 of 10

higarcia4SPJ6
Explorer
Explorer

@ronjonp I think chatgpt helped me a lot, it's just what I was looking for.

 

(defun c:Movee ( / blockname sset)
(while
(not (tblsearch "block" (setq blockname (getstring "\nEnter Block Name: "))))
(prompt "\nNo such Block name defined in this drawing. Try again:")
)
(if (setq sset (ssget "X" (list (cons 2 blockname))))
(progn
(setq b (ssname sset 0))
(setq insertionPoint (getpoint "\nEnter new insertion point: "))
(vla-put-insertionpoint (vlax-ename->vla-object b) (vlax-3d-point insertionPoint))
(princ (strcat "\nSelected " (itoa (sslength sset)) " instances of block \"" blockname "\"."))
)
(prompt "\nNo insertions of that Block in this drawing.")
)
(princ)
)

0 Likes