AutoCAD Visual LISP / AutoLISP :: Find And Replace Unique Attributes Using Script?
Jun 7, 2010
I have a “PART” block with attributes tags “PARTMARK” and “SHEAREDFROM” inserted 5 to 10 times in 10 to 50 drawings.
The “PARTMARK” value is always a unique number entered in autocad.The “SHEAREDFROM” value is calculated in Excel and exported to a “SHEARED.txt” file.
In each “PART” block I need to replace the “SHEAREDFROM” value based on the unique “PARTMARK” value, using a script that uses (or incorporates) the values from the “SHEARED.txt” file.
So far the only solution I’ve come up with is having a unique value for the “SHEAREDFROM” and –attedit to change the values in a script. However if the script doesn’t encounter a "K20-1S" in the first drawing it errors out and doesn’t proceed to the next. Below is an example of my rudimentary script.
(command "-attedit" "n" "n" "PART" "SHEAREDFROM" "K20-1S" "K20-1S" "8-60x192")
(command "-attedit" "n" "n" "PART" "SHEAREDFROM" "K20-2S" "K20-2S" "2-60x144")
(command "-attedit" "n" "n" "PART" "SHEAREDFROM" "K20-3S" "K20-3S" "2-60x132")
(command "-attedit" "n" "n" "PART" "SHEAREDFROM" "K20-4S" "K20-4S" "4-60x120")
(command "-attedit" "n" "n" "PART" "SHEAREDFROM" "K20-5S" "K20-5S" "0.7-60x120")
I’m assuming I need LISP to do this, but my LISP skills are limited. I think I would need a setq for each unique shearedfrom value (setq K20-1S (“8-60x192”))? Then somehow search each drawing for the unique shearedfrom value to replace.?
View 9 Replies
ADVERTISEMENT
Jan 25, 2012
I'm looking for a lisp routine that can find and replace multileader text.
I want to replace "T." with "T+" and "B." with "B+".
All the multileaders are on layers with a suffix of "-elev".
View 9 Replies
View Related
Jul 17, 2013
I having real difficulty finding a lisp that will find and replace blocks. There are plenty out there and AutoCAD 2013 and lower has a Find and Replace Blocks. However, the frustrating catch is I can seem to find a routine that will allow me to replace only those blocks that I select with a selection set of my choosing. The built in function replaces all of them and will not let you exclude some. We have PID drawings that we want to replace valves on, but not all valves. We don't want to rename. We don't need to BEDIT the existing block.
1) Pick group of blocks
2) specify a new block that will replace all instances of old block
3) replace inserted block with different block. Leaving others alone.
I'm thinking this should be easy, but my search has failed. The blocks in question are not dynamic or attributed either.
View 3 Replies
View Related
Feb 10, 2011
Is there a lisp or script program that will find and replace pre-defined text/mtext value of eg " issued for tender " for "issued for construction" without having to select anything.
View 9 Replies
View Related
Dec 11, 2012
how I could open an external .CSV file which is assigned to a variable called INFOFILE and scan line by line and replace each instance of the string "WIDGETTE" with the string "WIDGET"? I assume the function vl-string-subst woud be involved.
View 9 Replies
View Related
Sep 16, 2002
I am trying to globally find and replace text in Autocad 2000 drawings. If I have a folder containing 10 Autocad files, I want to open every file in that folder, while in each file, search for a certain line of text and replace that text, then close that file, open the next and find/replace text in that file.
I've created an autolisp file that allows me to open all the files in a certain folder, but I can't find any way, either thru autolisp or scripts, to allow me to find and replace text in each autocad drawing without using Autocad's "find" command to manually enter the text when each drawing is open.
I want to setup the autolisp file to accept input up front, save the "old text" and "new text" to variables, then use those variables as the lisp routine is running.
This version was used to automate creating PDF files. The command 'PDF' is a command from another Lisp file.
View 9 Replies
View Related
Feb 22, 2012
We've recently converted all our microstation drawings to autocad now that the company has decided to go with one cad program company wide.
One of the issues we are having after getting the drawings back from the this co. converting them is the cells to blocks convertion inside the drawing. when we open a drawing and see a "Fuse" block for instance and if it a has multiple inserts, it named them:
Fuse
Fuse_1
Fuse_2 etc....
is there a lisp routine or some command that would replace the "Fuse_*" blocks with "Fuse"..I've been searching the forums and know about the express tool Replace Block but need to be able to automate somehow.
I thought about trying to rename each of the "Fuse_*" but of course it won't let you rename to a block name that already exists..
View 1 Replies
View Related
Oct 5, 2011
I am looking for a routine that will replace all blocks named "DgnMisc_nodepoleind" with a block named "DgnMisc_nodepoleind2" keeping the insertion point. I could use (command "-insert" "DgnMisc_nodepoleind=Y:/ACAD2007/DA settings/Library_new_scale1/DgnMisc_nodepoleind2.dwg" NIL ) but my problem is that the block I want to replace is used on two different layers and I only want to replace the ones on layer "TPSYM01".
View 3 Replies
View Related
Aug 7, 2012
I have a dynamic block that has a nested temporary block inside it. What I am wanting to do is replace the temporary block with the permanent block. I have tried several different variation of coding but I cannot seem to get this bad boy to work. have used:
(vla-put-name (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))) "tempBlockName") "newBlockName")
this gives me a duplicate names error.
View 1 Replies
View Related
Nov 18, 2011
I have this snippet that inserts a block “Exit_Arrow”. The block has one attribute. Is it possible to force the attribute to remain at “0” rotation regardless what angle the bock is rotated?
(defun C:Exit_Arrow (/ LA DS)
(setq LA (getvar "clayer"))
(setq DS (getvar "dimscale"))
(C:TTEXT)
(command "._insert" " Exit_Arrow " pause DS "")
(setvar "clayer" LA)
(princ))
Is it possible to create blocks whose attributes remain at "0" rotation regardless the host block's rotation?
View 9 Replies
View Related
May 16, 2013
I isolated 3 attributes as you can see with my code. My object is too take the value of blkDESC1 and set it as blktag, and then take blkDESC2 and set it as blkDESC1, and erase blkDESC2.
(defun c:aup (/ dxf ent dxf1 ent1) (defun dxf (code ent) (cdr (assoc code (entget ent))))
(progn (if (and (setq ent (car (entsel "
Select an Attributed Block: ")))
(eq "INSERT" (dxf 0 ent))
[code]........
View 1 Replies
View Related
Jul 11, 2013
1) I want to search the drawing for the pre-define block names given in the program.
2) If the are there, I want to replace them with the new version.
3) Program replaces the first block it finds, then tries to insert that block.
View 9 Replies
View Related
Apr 26, 2012
I want to know if it's possible to replace a drive by an environment variable in a search path in the profile. For example:
to replace C:Program FilesAutodeskAutoCAD Mechanical 2012Acadm by %LOCAL DRIVE%Program FilesAutodeskAutoCAD Mechanical 2012Acadm.
View 5 Replies
View Related
Nov 26, 2012
Is there a way to modify this script so you don't have to manually choose the blocks. Instead have it find all block names starting with "Supply Diffuser 24x24" and replace them with a block in the drawing named V01.
(defun C:CHANGEBLOCKS(/ printDebug ssAll ssAllTotal ss ssTotal ssCount ssCount2 ssTotal ssMainBlock ssMainBlock entListMainBlock ssBlocks entListBlock entListBlock2 entElementNewBlock entElementOldBlock entElementOldBlock2 oldBlockName) ;PROGRAM CHANGES MULTIPLE BLOCKS ;WRITTEN BY --- RAUL BENITEZ ;Command reference ;subst - returns a list with a new item substituted for every occurrence of an old item ;quote (or ') - easy way to make the string into a list. ;cdr - returns a list containing all but the first element of
[code].......
View 6 Replies
View Related
Jun 20, 2012
I was able to write a LISP that replaced each node with a block of my choice.However, now I need to find a way now to replace the blocks with different blocks.Each point shares the exact same block called "PILE". Different blocks are on different layers and have 11 different colors. I'd like to replace blocks on layer 1 with a block called "1" and blocks on layer 2 with a block called "2" and so on.I was hoping there would be an easy way to do this in LISP, but I've been unable to get any of my scripts to work.
I've attached a link that visualize what my drawing is currently looking like: [URL] ......
View 2 Replies
View Related
Sep 12, 2011
There is a lisp function to replace all occurrences of a character within a string?
In short, as the Replace command in Visual Basic
For example, to replace all "x" to "*":
"34x59+60x3" -> "34*59+60*3
View 6 Replies
View Related
Aug 6, 2013
I have a block named "WD_MLRH". There are 3 specific attributes which I want to change in it. The attribute names are.
RUNGCNT, RUNGDIST and RUNGFIRST.
RUNGCNT will = 20
RUNGDIST will = 1.0 (or 1 will suffice)
RUNGFIRST will be decided by a user input.
Something along the lines of...
(setq RUNGFIRST (getint "Enter first rung number: "))
I'm sure this is completely wrong, but i hope that portray what I'm trying to accomplish.
View 9 Replies
View Related
Jan 5, 2012
I've been trying tons of different solutions to solve this problem: insert a block that has an attribute which happens to be the last object id.
This is the best code I tried so far but without any succss.
(defun c:q1()
(command "_.PLINE")
(while (= (getvar "CMDNAMES") "PLINE")
(command pause)
[Code] .....
View 9 Replies
View Related
Sep 12, 2013
I have searched the web and the Autodesk Discussion Group for a LISP Routine that allows me to convert all attributes in a drawing to Layer 0 but i have had no luck. It would be great if the LISP could edit xrefs as well although not sure if this is possible.
**BATTMAN command will take too long for the hundreds of blocks, xrefs and drawings i need to edit.
View 2 Replies
View Related
Mar 1, 2013
I need a function that will allow me to do a "divide" with blocks but I need the single attribute to remain intact.
I need the blocks to align with object and keep the attribute. I did get it to work with constants but the function that I need to run next failed because of the constant. My variable is preset and locked.
View 9 Replies
View Related
Oct 16, 2012
I downloaded a lisp routine that will align block attributes. The problem is I can only select the attributes one at a time. I'd like to be able select multiple attributes using the selection window or a crossing window, but I haven't had much luck. If you use the AEATTSHOW command, it give you a prompt to "select using window" by pressing W. I'd like to have the same functionality for my Align attributes routine.
Below is the portion of code I currently have to select attributes one at a time:
;* Select all attributes to align with the parent selected above and add the attribute entname and the block
;* entname to a list in format ( (AttrEntName BlkEntName) (AttrEntName BlkEntName) (AttrEntName BlkEntName) )
;*
while (/= TempAttr nil)
(setq
TempAttr (nentsel "
Select Attributes to align: ")
[Code] .........
View 5 Replies
View Related
Oct 11, 2011
I have to go through quite a few drawings and extract the attribute vales of the whole drawing and then a subset contained within a couple of polylines.
The whole drawing is Ok as I can use at out or the data extraction, but its the ones contained within a polyline. How do I do that?
View 9 Replies
View Related
Nov 3, 2013
How I can modify this code to create a block, ask for a new name for the block, then add the attributes listed inside the code below to the new created block. The lisp does a wonderful job - however, it only works if you already have a block created. We are in the process of drawing components and making blocks one by one, so it makes sense to add the attributes automatically when the block is created. We currently have over 500 components to create as a block and set the attributes to each one by one.
Also I would like to know, If Fields can be used inside the lisp routine. That way we can always have access to the attributes from outside the block and change values for all the blocks at once.
(defun c:addattribs ( / blk def ) (while (not (or (= "" (setq blk (getstring t "
Name of block to update: "))) (tblsearch "BLOCK" blk) ) ) (princ (strcat "
Block "" blk "" not found.")) ) (if (/= "" blk) (progn (setq def (vla-item (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object))) blk)) (vla-addattribute def (getvar 'textsize) acattributemodelockposition "New Attribute 1" (vlax-3D-point 0 0) "NEW_TAG1" "New Value 1" ) (vla-addattribute def (getvar 'textsize) acattributemodelockposition "New Attribute 2" (vlax-3D-point 0 (- (* 1.5 (getvar 'textsize)))) "NEW_TAG2" "New Value 2" ) (command "_.attsync" "_N" blk) ) ) (princ))(vl-load-com) (princ)
View 9 Replies
View Related
Aug 8, 2012
I know how to retrieve the entity information from the block, but can't figure out how to write the loop statement to loop, look for first attribute, assign to a variable, goto next attribute, assign to different variable, etc., etc...
In my research, most programs I've seen it execute the loop, assign to a variable, then print/put that data somewhere, loop again and utilize the same variable to print/put the next data somewhere.
I would like each attribute within a block to be assigned a separate variable.
View 7 Replies
View Related
Mar 19, 2013
I have an interesting challenge. I am tasked with updating old drawings. The only difficulty that I've run into with the old files are that the TitleBlocks are all done with all of the attributes are named "SPEC". There are 90 attributes. I'm really struggling with getting each attribute's value and then storing the value to a variable so that I can then put that value into a new TitleBlock. The old TB will be deleted to avoid future confusion in the file.
(To clearify, the old TitleBlock is in model space, while there are actually nine new TitleBlocks all in seperate paper space Layouts, and this program may have to run on hundreds of files.)
getting the values from the Old TB. I need them in order of first to last or last to first (either way will work since I have the variable names in a list that can be reversed if necessary.)
simple function to read through the block's attributes in order and store the attribute's value to a variable name in the seperate list (also in order)?
View 5 Replies
View Related
May 21, 2013
I am testing de new version of autocad 2014 and i have a problem with lisp.
when i use (command "_insert" "block1" pt1 "" "" "" obj1 ).
The block is inserted but without value. In the old version work.Some variable that has to change?
View 3 Replies
View Related
Oct 15, 2013
How i can filter attributes string value.
How i set the layer name is = attributes string value.
Example:
A attributes string value is R8 .all these string is set the layer name is same string value(R8).
View 1 Replies
View Related
May 9, 2013
I have 40 pages in one set of drawings and would like to rev-up the drawings. i will put same texts in same locations in the title blocks.
View 9 Replies
View Related
Sep 5, 2013
I'm using a blocklibrary, where I stored all my blocks, most of them have attributes.
Now I'd like to simplify my workflow and want to update the blocks that I inserted in a drawing trough LISP.
Is there a way to update all inserted blocks and attributes of the whole drawing a once? The idea is, that the LISP checks the whole blocklibrary and updates the inserted blocks that to not match with the once from the library.
View 9 Replies
View Related
Feb 27, 2013
We wanted to automatically fill a block's attributes from a selection in Excel. I have a piece of code that has the user select/pick a block to fill. What I want is for the selection to fill multiple blocks in an active drawing. Some of the blocks are the same - which means the same tags/attributes. I've included the code that allows the user to select the block and throws the Excel selection to certain attributes.change the code so that
1) I don't have to manually select blocks - it will find them.
2) One cell (from Excel) will go to multiple blocks - some are same block name.
3) An IF statement that if a certain cell isn't blank/nil
(pretend it would be (nth 21 vl) change DESC11 to XYZ and DESC12 to ABC. For Block namesake we'll call one, BLOCK1 (say it has 3 instances and gets different info in each case) BLOCK2 (say it has 2 instances, also gets different info) BLOCK 3 AND 4 both have an attribute - DESCAA1 that gets different info from Excel.
(defun C:AUTOFCM (/*error* adoc attribs blkobj enExcelapp Sel Sht Rng vl Wbk ) (defun *error* (msg)(if adoc (vla-endundomark adoc)) (if (and msg(vl-positionmsg '("console break""Function cancelled" "quit / exit abort") ))(princ msg)(princ "Error!") ) gc) (princ) ) (or adoc (setq adoc (vla-get-activedocument (vlax-get-acad-object))) ) (vla-startundomark adoc) (alert "Select a range of cells in Excel.") (setq ExcelApp (vl-catch-all-apply (function(lambda ()vlax-get-or-create-object "Excel.Application") )) ) ) (if (vl-catch-all-error-p(setq Wbk(vl-catch-all-
[code]....
View 1 Replies
View Related
Jan 4, 2012
i am trying to restrict users from modifying certain attributes in a block,i can create the blocks with some of the attributes on locked layers, but then autocad pops up an annoying alert box, is there a way to disable this? the other option i can think of is to redefine the commands *ddedit, *attedit, *ddatte,*attipedit,
View 5 Replies
View Related