Jump to content
notredave

Would appreciate lisp to change attributes across multiple drawings

Recommended Posts

notredave

Good morning all,

 

I would appreciate it very much if someone or knows of a lisp to change part of an attribute in title block across entire directory. Here is my example:

I have 340 loop diagrams with an example of first line reading LOOP DIAGRAM-HS-6521. I need to take the dash out between DIAGRAM and loop number and replace it with a space. I tried using Lee Mac's BATTE.lsp but it didn't work, it took out everything after DIAGRAM. Is there anything out there that would help me to replace that dash with a space keeping the rest intact. I have 340 drawings in directory that need to be fixed.

 

Thank you all in advance,

David

Share this post


Link to post
Share on other sites
notredave

Thank you rlx, but it did not work. It prompted me for directory and processed drawings. I don't know what it did and did not create .bak file. It just updated drawings and they saved but with no back up and again, I have no idea what it did. I was hoping to have a dialog box asking me what I want to accomplish in case I wanted to change something else. But thank you very much for your time and effort

 

Share this post


Link to post
Share on other sites
rlx

have other routines with more options but they are highly specialized for my company's drawings. This one I made as a sort of roadrunner for the highest possible speed and change text strings are hard coded on line 50/51

 

; string substitution list , for now hard coded (for testing)
  (setq ssl '(  ("DIAGRAM-" "DIAGRAM ")  ))

 

have you opened any drawing to check if it worked? if it didn't work... I'm sorry ... (text not on locked layer or something?)

 

gr. Rlx

Share this post


Link to post
Share on other sites
notredave

rlx,

I copied 9 drawings from working directory to a test directory on hard drive. The initial drawing I opened to start lisp, it did not work on but I opened the other 8 drawings and it worked! I am puzzled why it said that it processed 9 drawings but the drawing I have opened, which is part of the 9 didn't update with lisp. Is there a way that it could create a .bak? That way, if something goes terribly wrong, I can rename .bak to .dwg to go back to. I get concerned when I don't have a .bak with earlier date to revert back to. But again, it did work on 8 of 9 drawings. Thank you much rlx

Share this post


Link to post
Share on other sites
rlx

working with odbx it only processes drawings that are not already open. If Í test a program I first make a copy of the folder. You can also use a batch program and a scriptfile and use the normal autocad commands to make sure a bak file is created. Or in case of this routine add a line to also save a copy. That's just the way odbx works... if speed is what you want , speed is what you get by leaving out all the extra baggage. I have enough trust in my appie it does what it's suppost to do but on top of that , where I work , when drawings are checked out , we receive a copy in the project folder and when we're done and all is checked & approved , the document control program replaces the drawing on our as built server with the drawing from the project folder and cleans up the project folder.

Share this post


Link to post
Share on other sites
notredave

rlx, thank you for detailed explanation. Question for you, how would this lisp work without a drawing being open to start lisp, I'm just curious. Thanks again for helping me out and explaining things to me. This lisp file is just so overwhelming to me with everything in it. That's the part that scared me but it did work! Thank you!

Share this post


Link to post
Share on other sites
rlx
Posted (edited)

replace init section in program with this to create a bak file :

 

;--- Init ----------------------------------------------- Begin of Init section -------------------------------------------------- Init ---

(defun _init  ()
  (vl-load-com)  (setq err *error*)  (defun *error* (s) (princ s)(_exit)) (defun _exit () (odbx_releaseall)(setq *error* err)) (odbx_init)
  ; string substitution list , for now hard coded (for testing)
  (setq ssl '(("DIAGRAM-" "DIAGRAM ")))
  (if (and (setq sf (getfolder "Select source folder for drawings")) (vl-consp (setq dwg-list (fido sf))))
    (progn (setq start (car (_vl-times)))
    (princ (strcat "\nProcessing " (setq l (itoa (length dwg-list))) " drawings..."))
    (foreach dwg dwg-list (make_bakfile dwg)(change_text_string dwg))
    (princ (strcat "\n\nProcessed " l " drawings in " (rtos (/ (- (car (_vl-times)) start) 1000.) 2 4) " secs.")))
    (princ "\nNo files to process...")
  )
)

; test : (make_bakfile (strcat (getvar 'dwgprefix)(getvar 'dwgname)))
(defun make_bakfile (dwg / d err)
  (if (and dwg (eq (type dwg) 'STR) (setq d (findfile dwg))
       (not (vl-catch-all-error-p (setq err (vl-catch-all-apply 'vl-file-copy (list d (strcat (substr d 1 (- (strlen d) 3)) "bak")))))))
    (princ "\nBak file created")(princ (vl-catch-all-error-message err))))
   
(defun c:ct2 ( / dwg ssl )
  (setq ssl '( ("DIAGRAM-" "DIAGRAM ") )) ; ssl = '( ("oldstr1" "newstr1") ("oldstr2" "newstr2") ....) , case sensitive
  (setq dwg (strcat (getvar 'dwgprefix)(getvar 'dwgname)))
  (make_bakfile dwg)
  (change_text_string dwg)
  (princ "\nDrawing processed")
  (princ)
)

;--- Init ------------------------------------------------ End of Init section --------------------------------------------------- Init ---

 

type ct2 on command line to process current drawing

 

gr. Rlx

🐉

Edited by rlx

Share this post


Link to post
Share on other sites
notredave

rlx, you are the man!!! Thank you so much, it all works. I appreciate you taking time out while at work to help me. Have a great day!

Share this post


Link to post
Share on other sites
rlx

You're quite welcome. Not sure why Lee's program isn't working because it's far superior to mine which is more of a lite-version , I made mainly because I didn't need all the extra options master Lee's version has and also just practice training because I wanted to know how it worked.

Share this post


Link to post
Share on other sites
notredave

rlx, you did an excellent job. I spoke to soon. If you can do me a favor and test a drawing of yours that is open and try ct2 after you load the lisp. It did not change current drawing open but no biggie, just wanted to let you know. Thank you

Share this post


Link to post
Share on other sites
rlx

ah, your right... should have tested that before I pressed send... awell , probably easy fix , but for now , I press 'send myself home' ... come back2U later alligator

Share this post


Link to post
Share on other sites
rlx

hope this one works better , also when drawing is allready open

 

RlxOdbxChangeText.lsp

Share this post


Link to post
Share on other sites
notredave

I will try it. Thank you very much

 

Share this post


Link to post
Share on other sites
BIGAL

rlx did you read the blog section about using scriptpro without opening dwgs, posted yesterday, downloaded scriptpro to give it a try

Share this post


Link to post
Share on other sites
rlx
2 hours ago, BIGAL said:

rlx did you read the blog section about using scriptpro without opening dwgs, posted yesterday, downloaded scriptpro to give it a try

 

Hi Bigal , haven't read it yet , will do. Doubt I can download it here at work because (almost) all downloads are blocked , all new installations are blocked (100% guarantee) when program isn't member of company's white list , down to the last dll file. In fact , our 'cad herder' has to move heaven and earth to even get 1 registry value changed , that has to be approved and can take up to 3 months (and that's if he's lucky) and of course he has to start all over again with the next windows update... oh what a joy it is to work here.... 'Now they're talking about blocking all excel macro's. I'm just waiting for the day visual lisp is going to be blocked and we're all have to work with AutoCAD LT (or paint). But thank you for the tip , much appreciated as always!

Share this post


Link to post
Share on other sites
Lee Mac
Posted (edited)
On 3/14/2019 at 11:47 AM, notredave said:

I need to take the dash out between DIAGRAM and loop number and replace it with a space. I tried using Lee Mac's BATTE.lsp but it didn't work, it took out everything after DIAGRAM.

 

The current version of my BATTE lisp can unfortunately only substitute one value with another, it cannot replace part of an attribute value.

Edited by Lee Mac

Share this post


Link to post
Share on other sites
rlx
Posted (edited)
11 hours ago, BIGAL said:

rlx did you read the blog section about using scriptpro without opening dwgs, posted yesterday, downloaded scriptpro to give it a try

 

@Bigal , have read the post and they're talking about the AutoCAD Core Console. My RlxBatch appie already has this capability (and it also does plain scripts in SDI & MDI and odbx and publish).

 

Downside of the AutoCAD core is no visual lisp commands , just plain vanilla lisp and (most) AutoCAD commands. But for the speed demons among us... read what's in store with the AutoCAD Core :P

 

 

 

thanx Bigal!

 

🐉

Edited by rlx

Share this post


Link to post
Share on other sites
maratovich

notredave
Did you find a solution without opening all the files?

Share this post


Link to post
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
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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