Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Find a Block and get it's Insertion Point

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
AR12
8868 Views, 11 Replies

Find a Block and get it's Insertion Point

I'm working on a program and I have a part of it that I'm having trouble finding a way to do. I did do a search but I couldn't find what I was looking for.

 

How can I find a block with a specific name and get what the coordinates are? What we have is our Bill of Material is attributed blocks. I am attempting to change the first one. Well all of the lines that list the parts are seperate blocks with the same name. Now the Top Line of the Bill of Material is a different named block. If I can find the coordinates of this block I can then select the first line to do what I need to.

Thanks,
Adam Richardson

If needed: AutoCAD 2017 User using Visual LISP for editing LISP and DCL files
11 REPLIES 11
Message 2 of 12
devitg
in reply to: AR12

Please upload a sample dwg in 2008 or less
Message 3 of 12
Kent1Cooper
in reply to: AR12


@AR12 wrote:

....

How can I find a block with a specific name and get what the coordinates are? ....


In condensed terms, if there's only one Block by that name in the drawing:

 

(cdr (assoc 10 (entget (ssname (ssget "_X" '((2 . "YourBlockName"))) 0))))

Kent Cooper, AIA
Message 4 of 12
AR12
in reply to: Kent1Cooper

Kent,

Thank you very much. That's what I was looking to do.

Thanks,
Adam Richardson

If needed: AutoCAD 2017 User using Visual LISP for editing LISP and DCL files
Message 5 of 12
LISPlearner
in reply to: AR12

EDIT: replied to wrong post

Message 6 of 12
LISPlearner
in reply to: Kent1Cooper

I have come across this thread and it is about the closest i can find to the issue i need to resolve. 

 

Basically, what i want to be able to do is grab a block by name (TOWER) then move the entire drawing to 0,0 based on the TOWER blocks insertion point. 

 

Any idea how i would grab that insertion point and then select all in the drawing, then move to 0,0 with the insertion point as the basepoint?

 

Thanks in advance for any help

Message 7 of 12
Kent1Cooper
in reply to: LISPlearner

Try this [untested], in simplest terms:

 

(command

  "_move" "_all" ""

  (cdr (assoc 10 (entget (ssname (ssget "_X" '((2 . "TOWER"))) 0))))

  "0,0,0"

)

 

BUT:  That assumes there is such a Block in the drawing, and only one.  And it should be run in the space that Block is Inserted in, and will Move only stuff in the current space, on un-locked Layers, and should be done with running Object Snap off.  All those circumstances can be controlled for, if the situation may vary when you run it.

Kent Cooper, AIA
Message 8 of 12
LISPlearner
in reply to: Kent1Cooper

I actually just got this sorted out! Your approach is different, and perhaps something i can learn new techniques from! Thank you so much for the help!

 

I never would've thought of defining the points within the command. I had always looked at it as they needed to be defined, then could be called for. 

 

Here is what I ended up with, seems to work with limited testing. 

Thank you again!

 

I'm quite happy i was able to get this one together and working on my own with just a few lines from this thread! (i'm pretty new to coding)

 

 

(defun c:twr0 (/ inspoint)

  (if (setq inspoint (cdr (assoc 10 (entget (ssname (ssget "_X" '((2 . "TOWER"))) 0)))))
      (command "_move" "all" "" inspoint "0,0" "") 
  )

 (princ)

)

 

Message 9 of 12
Kent1Cooper
in reply to: LISPlearner

Looks good except for the extraneous Enter [""] at the end of the Move command.  Giving it the destination point completes the command, so the "" will recall the latest command, not the Move used internally but the latest one used outside  prior to running this routine, whatever that was.  If you're lucky, it was something like Redraw or Regen that won't ask you for anything, but otherwise you could be surprised.

Kent Cooper, AIA
Message 10 of 12
LISPlearner
in reply to: Kent1Cooper

This does work much better! I have a hard time with when the "" (enter) should be added at the end of the command within a routine. I appreciate your input! Thank you very much! This is working great now. 

Message 11 of 12
Kent1Cooper
in reply to: LISPlearner


@KDAWG1213 wrote:

.... I have a hard time with when the "" (enter) should be added at the end of the command within a routine. .... 


Just run any command at the command line, and see what it asks for and after what input it's finished.  Many people seem to get the mistaken impression that a "" is needed at the end of all  commands in AutoLisp (command) functions.  I assume it's from the fact that some  commands [such as LAYER and LINE and PLINE], after you've told them to do something, let you continue, typically by going back to a "base" prompt offering the various options to do another  something if you want to, and Enter is the way to tell it you're done.  For those kinds of commands, you do need the extra "", but Move doesn't have any options or ask for anything further after you've told it where to go.

Kent Cooper, AIA
Message 12 of 12
LISPlearner
in reply to: Kent1Cooper

That is by far the best explanation of when to use that that i've read. Thank you once again for your insights! This is definitely information i will use and pass on to others who are learning. Great piece of info. 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost