Jump to content

Help with scripts


baphometh

Recommended Posts

what scripts should I make to be able to automatically select objects with certain linetypes or colors and change its layer and set its properties to default?

Also, can scripts do a A3 size layout and insert title block?

Link to comment
Share on other sites

yes

like select a certain objects like a line with linetype "center" and transfer it to another layer and set its properties to default

can you give me a sample script?

Link to comment
Share on other sites

Well maybe something like this to change all "hidden" lines to "bylayer" -- can be modified similarly for colour and layer.

 

(defun getLT  (lt)
 (setq lLst "")
 (vlax-for layer
          (vla-get-layers
            (vla-get-activedocument
              (vlax-get-acad-object)))
   (if    (eq (strcase (vla-get-Linetype layer)) (strcase lt))
     (setq lLst (strcat  (vla-get-name layer) (chr 44) lLst)))))

(defun c:test (/ lLst)
 (vl-load-com)
 (getLT "Hidden")
 (setq lLst (vl-string-right-trim (chr 44) lLst))
 (setq ss (ssget "X" (list (cons 8 lLst)
    (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
      (cons 67 (- 1 (getvar "TILEMODE")))))))
 (command "_chprop" ss "" "LT" "BYLAYER" "")
 (princ))

Link to comment
Share on other sites

Thank you very much

Does this go on the script file?

CAn I also use this to select all the text in the drawing and set their properties like text size and font?

Link to comment
Share on other sites

The above is a LISP file and needs to be saved as a ".lsp" file in a notepad document.

 

You can run the above by using "_appload" in ACAD, or by going to "tools" "load application" and loading the file and then typing "test" at the command line.

Link to comment
Share on other sites

CAn I also use this to select all the text in the drawing and set their properties like text size and font?

 

The above could be modified to suit text changes also, but it might be easier to change the text by selecting all the text using maybe QSELECT and then changing the properties using the property sidebar.

Link to comment
Share on other sites

Thanks

But I was thinking of making the whole process automated and requiring no user input and intervention

I am working on standardizing multiple files and is there a way to make a lisp to edit all these in a single go

Link to comment
Share on other sites

Maybe if you could get a LISP to do what you wanted to one file, then use a script to open each drawing and run the LISP.

 

But I am not sure whether or not you can run custom commands within scripts. - probably not is my guess.

Link to comment
Share on other sites

If you give me your exact requirements - in terms of alterations to layers, colours, etc I could see if I could write a LISP to suit your needs. - This would save you the effort on each drawing.

 

You could then maybe use VBA to open the drawings and call the LISPs.

Link to comment
Share on other sites

ok

select all lines with linetype "center", put it into layer 0_center and set all its properties to "by layer"

:hidden lines to 1_hidden, by layer

:phantom lines to 1_phantom, by layer

red lines to 1_main1

green lines to 1_main2

set all text to romans, 3.75,center aligned

make a layout of A3, insert title block, make viewport

 

I'd really appreciate it if you help me.

Link to comment
Share on other sites

ok

select all lines with linetype "center", put it into layer 0_center and set all its properties to "by layer"

:hidden lines to 1_hidden, by layer

:phantom lines to 1_phantom, by layer

red lines to 1_main1

green lines to 1_main2

set all text to romans, 3.75,center aligned

make a layout of A3, insert title block, make viewport

 

I'd really appreciate it if you help me.

 

I could probably achieve the majority of the above, except for the A3 layout with titleblock and viewport... thats pushing it some.. :P

Link to comment
Share on other sites

This should help you somewhat :

 

(defun getLT  (lt)
 (setq lLst "")
 (vlax-for layer
          (vla-get-layers
            (vla-get-activedocument
              (vlax-get-acad-object)))
   (if    (eq (strcase (vla-get-Linetype layer)) (strcase lt))
     (setq lLst (strcat  (vla-get-name layer) (chr 44) lLst)))))

 (defun makelay (x)
   (if    (not (tblsearch "LAYER" x))
   (command "-layer" "M" x "")))

(defun c:test (/ olderr *error* vLst oVar lLst ss eLst)
 (vl-load-com)
 (setq olderr *error* *error* errtrap)
 (defun errtrap (msg)
   (if oVar (mapcar 'setvar vLst oVar))
   (setq *error* olderr)
   (princ))
 (setq vLst (list "CMDECHO" "CLAYER")
   oVar (mapcar 'getvar vLst))
 (setvar "CMDECHO" 0)
 (getLT "Hidden")
 (mapcar 'makelay '("1_hidden" "1_phantom" "1_main1" "1_main2"))
 (setq lLst (vl-string-right-trim (chr 44) lLst))
 (if (setq ss (ssget "X" (list (cons -4 "<OR")(cons 8 lLst)(cons 6 "HIDDEN")(cons -4 "OR>")
    (if (getvar "CTAB")(cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
 (setq i (sslength ss))
 (while (not (minusp (setq i (1- i))))
   (if (and (assoc 6 (entget (ssname ss i)))
        (not (eq "HIDDEN" (cdr (assoc 6 (entget (ssname ss i)))))))
     (ssdel (ssname ss i) ss)))
 (command "_chprop" ss "" "LT" "BYLAYER" "LA" "1_hidden" "")
 (setq lLst nil ss nil)) (princ "\n<!> No Hidden Lines Found <!>"))
 (getLT "Phantom")
 (setq lLst (vl-string-right-trim (chr 44) lLst))
 (if (setq ss (ssget "X" (list (cons -4 "<OR")(cons 8 lLst)(cons 6 "PHANTOM")(cons -4 "OR>")
    (if (getvar "CTAB")(cons 410 (getvar "CTAB")) (cons 67 (- 1 (getvar "TILEMODE")))))))
   (progn
 (setq i (sslength ss))
 (while (not (minusp (setq i (1- i))))
   (if (and (assoc 6 (entget (ssname ss i)))
        (not (eq "PHANTOM" (cdr (assoc 6 (entget (ssname ss i)))))))
     (ssdel (ssname ss i) ss)))
 (command "_chprop" ss "" "LT" "BYLAYER" "LA" "1_phantom" "")
 (setq ss nil)) (princ "\n<!> No Phantom Lines Found <!>"))
 (if (and (tblsearch "STYLE" "ROMANC")
          (setq ss (ssget "X" (list (cons 0 "TEXT,MTEXT")
         (if (getvar "CTAB")(cons 410 (getvar "CTAB"))
       (cons 67 (- 1 (getvar "TILEMODE"))))))))
   (progn
     (setq eLst (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss))))
     (foreach e eLst
   (entmod (subst (cons 7 "ROMANC") (assoc 7 (entget e)) (entget e)))
   (entmod (subst (cons 40 3.75) (assoc 40 (entget e)) (entget e))))
     (command "_regenall"))
   (princ "\n<!> No Text Found <!>"))
 (mapcar 'setvar vLst oVar)
 (setq *error* olderr)
 (princ))

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