Jump to content

Need solution to batch change only text on one layer in XXXX# of drawings to be by layer


SamuelA

Recommended Posts

Hello, I am an electrical engineering technician and I am trying to publish a giant stack of drawings from a vendor. Using my clients printing template it causes one layer's text to plot VERY bold. im aware of the SETBYLAYER command and id rather not have to open each one, quick select text from said layer, and run setbylayer. I have taken three semesters of autocad however lisps and scripts were not part of that curriculum, is there a way to run a lisp/script/macro/vba to do this for a folder? is there an even easier way to batch change the layer properties? 

 

if there were variables the layer would be layer "12" I would need only text from that layer, and would need it to run SETBYLAYER, and save/ close. 

 

any help would be appreciated it would save a ton of time. 

thanks, Sam

Link to comment
Share on other sites

How many drawings is "a giant stack" by the way?, and is this a one off task? It might be just as quick to open them all manually and run a LISP as trying to work out the accoreconsole (I haven't been too successful with it, but never had a lot of time to make it do what I want),

 

Below is a quick LISP that should do setbylayer to all the text on layer 12. Copy this to notepad and save as something like "mysetbylayerlisp.lsp", then use appload command add this file to the startup suit. Whenever you open AutoCAD this will be available to use. (this link http://lee-mac.com/runlisp.html has a better explanation and description).

 

Depending how many files you have, delete the last two ;; in your LSP file, save, and then open one of your giant stack... this should run when the drawing is opened, and you can just close the drawing again - might be just as quick as working out batch processes. However again Lee Mac might come to the rescue here with this http://www.lee-mac.com/scriptwriter.html (don't need to delete the last two ;; for this)

 

(defun c:resetbylayer ( / )
  (command "_.setbylayer" (ssget "_A" '((0 . "*TEXT")(8 . "12"))) "" "" "")
  (command "_.qsave")
)

;; (c:resetbylayer)

 

Edited by Steven P
Corrected code
  • Thanks 1
Link to comment
Share on other sites

33 minutes ago, Steven P said:

How many drawings is "a giant stack" by the way?, and is this a one off task? It might be just as quick to open them all manually and run a LISP as trying to work out the accoreconsole (I haven't been too successful with it, but never had a lot of time to make it do what I want),

 

Below is a quick LISP that should do setbylayer to all the text on layer 12. Copy this to notepad and save as something like "mysetbylayerlisp.lsp", then use appload command add this file to the startup suit. Whenever you open AutoCAD this will be available to use. (this link http://lee-mac.com/runlisp.html has a better explanation and description).

 

Depending how many files you have, delete the last two ;; in your LSP file, save, and then open one of your giant stack... this should run when the drawing is opened, and you can just close the drawing again - might be just as quick as working out batch processes. However again Lee Mac might come to the rescue here with this http://www.lee-mac.com/scriptwriter.html (don't need to delete the last two ;; for this)

 



(defun c:resetbylayer)
  (command "_.setbylayer" (ssget "_A" '((0 . "*TEXT")(8 . "12"))) "" "" "")
  (command "_.qsave")
)

;; (c:resetbylayer)

 

steven youre awesome for this, the stack is hundreds, but they are grouped in folders of 30-50, what does the double semicolon do, and removing it will result in what when running the app? additionally, I have that leemac tool loaded, if I load your script into it youre saying I wont have to delete the double semicolon? thanks

Edited by SamuelA
  • Like 1
Link to comment
Share on other sites

29 minutes ago, SamuelA said:

steven youre awesome for this, the stack is hundreds, but they are grouped in folders of 30-50, what does the double semicolon do, and removing it will result in what when running the app? additionally, I have that leemac tool loaded, if I load your script into it youre saying I wont have to delete the double semicolon? thanks

 

; tells lisp to ignore anything after it until next line. Basically used to make comments/notes inside of lisp.

If you uncommnet or remove the ; ; when you load the lisp it will then automatically run itself after loading.

 

  • Like 1
Link to comment
Share on other sites

What he said.....

 

 

(I tend to to use double ;; for comments since that is a bit more visible, a single one does the same thing... as does 100)

Link to comment
Share on other sites

Explaining a bit more it has a defun which is a little function that can contain like a 1000 lines of code but is called from the command line by typing resetbylayer, if you want it to run as part of load sequence hence the line (c:resetbylayer) without the double semicolon means run the defun, note its at end of code. A defun with c : means the name can be used as a command (defun restbylayer would need (resetbylayer) to work within in a lisp program.

 

Using accoreconsole is super fast, it edits a dwg without opening, you have to call a script so in this case the script file would have (load "resetbylayer") alternatively the script could just have.

(command "_.setbylayer" (ssget "_A" '((0 . "*TEXT")(8 . "12"))) "" "" "")

save 

Close

 

https://through-the-interface.typepad.com/through_the_interface/2012/02/the-autocad-2013-core-console.html

 

For this task I am old fashioned and use a CMD DOS function dir *.dwg >dwglst.txt /b to make a list of all the dwg's and use Word to convert to a script, get a coffee and watch or if lots go to lunch. PS always backup beforehand.

 

Edited by BIGAL
  • Like 1
Link to comment
Share on other sites

On 11/12/2021 at 10:28 AM, Steven P said:

How many drawings is "a giant stack" by the way?, and is this a one off task? It might be just as quick to open them all manually and run a LISP as trying to work out the accoreconsole (I haven't been too successful with it, but never had a lot of time to make it do what I want),

 

Below is a quick LISP that should do setbylayer to all the text on layer 12. Copy this to notepad and save as something like "mysetbylayerlisp.lsp", then use appload command add this file to the startup suit. Whenever you open AutoCAD this will be available to use. (this link http://lee-mac.com/runlisp.html has a better explanation and description).

 

Depending how many files you have, delete the last two ;; in your LSP file, save, and then open one of your giant stack... this should run when the drawing is opened, and you can just close the drawing again - might be just as quick as working out batch processes. However again Lee Mac might come to the rescue here with this http://www.lee-mac.com/scriptwriter.html (don't need to delete the last two ;; for this)

 


(defun c:resetbylayer)
  (command "_.setbylayer" (ssget "_A" '((0 . "*TEXT")(8 . "12"))) "" "" "")
  (command "_.qsave")
)

;; (c:resetbylayer)

 

hi steven I am getting syntax error when saving as a lisp, loading into startup suite, or running it as lisp individual load. 

history: 

 

Command: APPLOAD
resetbylayer.lsp successfully loaded.


Command: ; error: syntax error

 

any suggestions?

Link to comment
Share on other sites

Change  ;; (c:resetbylayer) to (c:resetbylayer) then reload into startup suite. Oh it may fail if layer 12 does not exist. As you want it to run automatically try this no need to make it a defun as it should run on open dwg.

 

(if (tblsearch "layer" "12")
(command "_.setbylayer" (ssget "_A" '((0 . "*TEXT")(8 . "12"))) "" "" "")
(princ "layer does not exist")
)

 

I have a autoload.lsp that is loaded on startup and has like 15 defuns, same amount of Autoload, plus runs 3 commands setting stuff. So only need 1 file in startup suite.

 

This is one I like blocks palette on our dwt is a pain. Note no blockspalette in Bricscad.

 

(if (wcmatch (vlax-product-key) "*Bricsys*")
(princ)
(command "BLOCKSPALETTECLOSE")
)

 

Edited by BIGAL
Link to comment
Share on other sites

1 hour ago, BIGAL said:

Change  ;; (c:resetbylayer) to (c:resetbylayer) then reload into startup suite. Oh it may fail if layer 12 does not exist. As you want it to run automatically try this no need to make it a defun as it should run on open dwg.

 



(if (tblsearch "layer" "12")
(command "_.setbylayer" (ssget "_A" '((0 . "*TEXT")(8 . "12"))) "" "" "")
(princ "layer does not exist")
)

 

 

 

this works flawlessly  Just have to open every drawing which is fine because I need to move a stamp on each one anyway. thank you so much this saves me so much time, 

 

another thing that has come up is the vendor used splines to revision cloud their changes, however I do not need them, if I wanted to delete all splines on layer "5"  in the same kind of way, would that be possible as well? would it be this below? in this post alone I have started to pick up on the language. 

(if (tblsearch "layer" "5")
(command "_.erase" (ssget "_A" '((0 . "*spline")(8 . "5"))) "" "" "")
(princ "layer does not exist")
)

 

 

EDIT: LOL nevermind that^ works too and I'm thankful this forum exists. 

Edited by SamuelA
Link to comment
Share on other sites

15 hours ago, SamuelA said:

hi steven I am getting syntax error when saving as a lisp, loading into startup suite, or running it as lisp individual load. 

history: 

 

Command: APPLOAD
resetbylayer.lsp successfully loaded.


Command: ; error: syntax error

 

any suggestions?

 

 

I was going to reply last night, must have forgotten to hit the send button, as I had it I have missed out a bracket in the first line, which causes the syntax error.

(defun c:resetbylayer) should be (defun c:resetbylayer ( / )

Take this line away and the last bracket ')', when the file is loaded as a drawing opens, like Big Al says AutoCAD will just see it as a list of commands and just does them rather than a function that can be called on later.

 

Big Als suggestion is better, adding in a check that the layer exists.

 

 

Looks like your erase spline will work, you don't need the * which is a wildcard, just spline

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