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

Need a Block Translator LSP

7 REPLIES 7
Reply
Message 1 of 8
gccdaemon
527 Views, 7 Replies

Need a Block Translator LSP

Hey guys, not a lot of time here to post, so I'll keep it short. I need a LSP routine that is just like the Layer Translator, but for blocks. I need this tool for swapping out blocks in survey files. I have a seperate "Block Library DWG's" with all my standard blocks, so I just need a means to translate them from these seperate files.

 

FYI I already have a block swap LSP, but i need the ability to pull the block definitions from the external files. (Just like Laytrans)

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
7 REPLIES 7
Message 2 of 8
3wood
in reply to: gccdaemon

I reckon using a script file is a good idea.

Just put lines like

INSERT BLOCK_A=BLOCK B, something like that.

Message 3 of 8
bhull1985
in reply to: 3wood

Yeah not sure if exactly this will fit your needs but maybe it will.
Allows for one click block swap, as i call it.

 

(defun C:swapblock ( / oldos cmdecho dxf en name doc)
(initerr)
(setvar "cmdecho" 0)
(setvar "osmode" 0)
(setvar "attdia" 0)
(setvar "attreq" 0)
(command "undo" "be")
(if 
(setq en (car (entsel "Select block to update:")))
(progn
(princ)
(setq name (cdr (assoc 2 (setq dxf (entget en)))))
(setq objx 1)
(if (= NAME NIL)
 (progn
 (alert "Entity selected is not a block. ")
));progn
));progn if

(if (= objx 1)
(progn
(command "_.insert" (strcat name "="))
;(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
;(vla-SendCommand doc (chr 27))
(princ)

);progn
);if
(princ "\n")
(princ (strcat "PIP Block " name " Redefined."))
(princ)

);defun

 HTH

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please use code tags and credit where credit is due. Accept as solution, if solved. Let's keep it trim people!
Message 4 of 8
gccdaemon
in reply to: gccdaemon

Thanks for the reply's. I already have a block swap LSP routine that can replace a block definition with another and purge the replaced block. What i'm looking for is something that will swap the block in the current DWG with a block definition from an external DWG (which I already have created).

 

I would use DRAWING STANDARDS but blocks are not part of that function. If I could find the layer translator programming, I might be able to modify it for blocks with assistance of course....lol.

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 5 of 8
p_mcknight
in reply to: gccdaemon

What kind of blocks are you updating?  I have two external redefine commands that I use.  One is a lsp that allows you to specify block names and an external file and then redefines the internal blocks with the block definitions in the external drawing.  It is a very simple program that does not work in all instances.  For example, it does not work with blocks including fields.  I am not sure how it would handle a block with a nested anonymous block or something that would require civil enablers.  I also have a .net program that does the same and works in all instances, however it causes errors in the block table that must be cleared via audit.  The errors dont cause any issues, they just must be cleared.  Does this sound more along the lines of what you would be looking for?

Message 6 of 8
gccdaemon
in reply to: p_mcknight

Go ahead and post both of them. I'm looking for something that will help me clean up surveys. I get a lot of survey blocks that don't match our symbology. I know that attributed blocks are a problem, but you can attsync them after the fact and change the values later. This would be something I integrate into the routine.

Andrew Ingram
Civil 3D x64 2019
Win 10 x64 Pro
Intel Xeon E5-1620
32 GB Ram
Message 7 of 8
p_mcknight
in reply to: gccdaemon

Attached are both versions as txt files.  The sr.txt is the .net version.  Note that it is commented out as I now use the lsp version at our work.  All of our blocks that we use it on are simple blocks so the the lsp version works fine for us.  You will also need to add in the appropriate imports for the .net to work properly.  The lsp is really fairly simple.  It opens the external drawing, gets the entity information in a list for all blocks, and then rebuilds and redefines the blocks using entmake in the current drawing (building up from the deepest nest to the top block).  As I stated, the simplicity opens up some vulnerability in the program so test it with the types of blocks you are using.  If you go with the .net version just make sure you aduit after running the command.  I did remove a (getfilepath) function from the lsp as you will need to get the external file path using your own method.  We use this to update our part views and as such our part numbers can be used to generate file paths.  It would be fairly easy to swap this out with a (getfiled) function in your use of it.  Hope this get you going in the right direction.  The best part is that it keeps us out of the design center which kills us when we use it in drawings with a few thousand block definitions.  Good luck.

Message 8 of 8
Gary_J_Orr
in reply to: gccdaemon

here is a snippet from an old routine that gets a block from another document and copies the definition into your current drawing:

 

well heck, copy/paste made a mess of the formatting for some reason, I'll attach it instead.

 

Open the attached txt file and paste the contents at the beginning or end of your existing lisp file.

 

when you need to aquire a block (at whatever line is appropriate within your existing lisp file) insert the following line:

 

(get-block-from-DWG filespec blockname)

 

replace filespec with the name of the resource file, and blockname with the name of the block to get from that file.

 

This was built for a single block insertion at a specific time while setting up a sheet file, but it can be modified to get a list of required blocks at one time easily enough.

Gary J. Orr
(Your Friendly Neighborhood) CADD/BIM/VDC Applications Manager
http://www.linkedin.com/in/garyorr

aka (current and past user names):
Gary_J_Orr (GOMO Stuff 2008-Present); OrrG (Forum Studio 2005-2008); Gary J. Orr (LHB Inc 2002-2005); Orr, Gary J. (Gossen Livingston 1997-2002)

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

Post to forums  

Autodesk Design & Make Report

”Boost