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.
Solved! Go to Solution.
Solved by Kent1Cooper. Go to Solution.
Kent,
Thank you very much. That's what I was looking to do.
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
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.
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) )
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.
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.
@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.
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.