Jump to content

Insert Blocks at Insertion Points of Selected Characters


nick777

Recommended Posts

Right now I have 15,000 drawings that use letters instead of symbols, an artifact of a now defunct CAD software that translated the letters into symbols. I'd like to remake this in AutoCAD by inserting blocks at the location of those letters.

 

I cannot find instructions on how to do this anywhere, and I need to add the following things to my code:

1 - Insert a set of blocks from another drawing.

2 - Select a specific letter from text in a specific layer in code

3 - Insert one of the newly inserted blocks at the insertion point of the letter

4 - Delete the character as it is no longer needed (unless it was replaced, then it wouldn't be there anymore)

 

Example: Import set of blocks from template drawing. Select from layer "Curb Valve" the character "R" from a piece of text in the layer (exact match preferred if possible). Replace this symbol with a block named "CurbValve."

 

I know you can get the X,Y of the text letter and manually type that in when you manually insert a block, so if you can detect this somehow and assign it to a variable, then use that variable to use as the insertion point of the block it would work. I just haven't been able to figure out how to do it programmatically.

 

Thank You!

Edited by nick777
removed code as it was not necessary.
Link to comment
Share on other sites

Pretty easy to get insert point of text using VL is a little easier sorry had to go back soon will finish code.

 

(setq thisdrawing (vla-get-activedocument 
                     (vlax-get-acad-object)))
(setq mspace (vla-get-modelspace thisdrawing))
(setq ss1 (car (entsel "\nSelect text ")))
(setq en (vlax-ename->vla-object sS1))
(setq lname (vla-get-layer en))
(setq anstxt (vla-get-textstring en))
; replace this later with a list say ((r "rev")(s "sect")) look up list
(setq blkname (getstring "\nEnter block name" ))
(setq ss2 (ssget "X" (list (cons 0  "Text")(cons 8 lname)(cons 1 anstxt))))
(setq inc (sslength ss2))
(repeat inc  
(setq obj (vlax-ename->vla-object (ssname SS2 (setq inc (1- inc)))))
(setq inspt (vla-get-insertionpoint obj))
(vla-delete obj) 
(vla-InsertBlock mspace InsPt blkName 1 1 1 0)
)
(setq ss1 nil
     ss2 nil)
(princ)

Edited by BIGAL
Link to comment
Share on other sites

Please read the CODE POSTING GUIDELINES and edit your post to include Code Tags.

 

SLW210, you may have to help with this one, as whatever code you are seeing is not so obvious, either in the post or as a ref in the CPG.

 

Oh, I see, he removed whatever code was there.

Edited by neophoible
didn't see it going
Link to comment
Share on other sites

I removed the code he was referring to because I didn't have anything useful to start with, just unrelated stuff.

 

BigAl, your solution does take care of #2-#4 when using manual selection, and I've found other code to insert the blocks as I needed in #1 which also works to insert all the blocks I need from my block library.

 

I'm looking to automate this to put in a script and the selection will be done maybe ~13 times per file for 12,000 files, to select different characters from different layers and insert different blocks. I'm not sure what you mean by how to edit your code to list this stuff, as I've read up on lists, but I've only been doing this for maybe 3 days and I'm pretty clueless as to how to make the right edits.

 

Also, most of the time, the selection will be blank, so it needs to skip that particular selection if there is no character. Thank you for your help.

Link to comment
Share on other sites

One other thing I'd like this to do is to explode the block after it is inserted. A few of the blocks have text in them that I'd like to be able to edit and I'd like to save the step of exploding each one. What change would enable that?

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