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

Can I change plot style with lisp?

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
3333 Views, 11 Replies

Can I change plot style with lisp?

Is there a way for me to change a layers plot style from one to another with
LISP?
We use named plot styles, STB's not CTB's.

I want to be able to create an icon that will change all layers with the
plotstyle "normal" to "black".
Is this possible with lisp?
11 REPLIES 11
Message 2 of 12
rebel
in reply to: Anonymous

Alex, the following code has no error checking, assumes the drawing is already in Style dependant mode, and Style "Black" is in the currently defined STB.
;;;
;;;James Buzbee
;;;
(defun jb:NormaltoBlack( / )
(setq layers(vla-get-layers(vla-get-ActiveDocument(vlax-get-acad-object))))
(vlax-for l layers
(progn
(if (= (vlax-get-property l 'PlotStyleName) "Normal")
(vlax-put-property l 'PlotStyleName "Black")
)
)
)
)
;;;
;;;
;;;
Message 3 of 12
scotts
in reply to: rebel

James,

 

I can get the lisp to load, but can't seem to get it to run.  Also can I repeat the code if I have multiple plot styles I want to replace (i.e. style_01 with black, style_02 with Screened50, etc...)

 

Your help is greatly appreciated!

 

-Scott

Message 4 of 12
pdx271
in reply to: Anonymous

Remove the "?" in VLIDE, there was a mystery question mark once i pasted into VLIDE.

It does not show here.

 

- I modified it for my needs.

 

 

(defun NormaltoFS (/)
  (setq layers (vla-get-layers
   (vla-get-ActiveDocument (vlax-get-acad-object))
        )
  )
  (vlax-for l layers
    (progn
      (if (= (vlax-get-property l 'PlotStyleName) "Normal")
 (vlax-put-property l 'PlotStyleName "Full Saturation")
      )
    )
  )
)

Message 5 of 12
SoftwareSupport
in reply to: Anonymous

Not sure if you guys are still alive but...

 

What if I wanted to exclude a few layers from this routine:

 

(defun c:WPS    (/)
  (setq    layers (vla-get-layers
         (vla-get-ActiveDocument (vlax-get-acad-object))
           )
  )
  (vlax-for l layers
    (progn
      (if (= (vlax-get-property l 'PlotStyleName) "Normal")
    (vlax-put-property l 'PlotStyleName "Medium")
      )
    )
  )
)

Message 6 of 12
pbejse
in reply to: SoftwareSupport


@softwaresupport wrote:

Not sure if you guys are still alive but...

 

What if I wanted to exclude a few layers from this routine:

 


 

(defun c:WPS    (/)
  (setq    layers (vla-get-layers
         (vla-get-ActiveDocument (vlax-get-acad-object))
           )
  )
  (vlax-for l layers
    (progn
      (if (and (= (vlax-get-property l 'PlotStyleName) "Normal")
               (not (member (strcase (vla-get-name l)) '("EXCLUDEDLAYER1" "EXCLUDEDLAYER2"))))
    (vlax-put-property l 'PlotStyleName "Medium")
      )
    )
  )
)

 

HTH

Message 7 of 12
SoftwareSupport
in reply to: pbejse

That did it! Problem solved. Thanks a ton!

Message 8 of 12
gustavobernardi
in reply to: pbejse

I've tried changing "Normal" with "None" and "Medium" with my plotstyle name, but it doesn't work...

 

I would like to make a routine that defines a specific plot style in the model if the current plotstyle is "None"

 

What a need to modify?

 

TIA

 

(defun c:WPS    (/)
  (setq    layers (vla-get-layers
         (vla-get-ActiveDocument (vlax-get-acad-object))
           )
  )
  (vlax-for l layers
    (progn
      (if (and (= (vlax-get-property l 'PlotStyleName) "None")
               (not (member (strcase (vla-get-name l)) '("EXCLUDEDLAYER1" "EXCLUDEDLAYER2"))))
    (vlax-put-property l 'PlotStyleName "Ringo 1-50")
      )
    )
  )
)
Message 9 of 12
pbejse
in reply to: gustavobernardi


@gustavobernardi wrote:

I've tried changing "Normal" with "None" and "Medium" with my plotstyle name, but it doesn't work...

 

I would like to make a routine that defines a specific plot style in the model if the current plotstyle is "None"

 

What a need to modify?

 


If the plot stylename "None" "Medium" and "Ringo 1-50" exists, there is no reason why the snippet would not work.

 

Try setting the current plot stylename to "Ringo 1-50" before running the code, easiest way is with.

 

 

..
(command "-plotsyle" "_Current" "Ringo 1-50")
..

HTH

 

 

Message 10 of 12
gustavobernardi
in reply to: pbejse

Humm, interesting... Now I see. My problem is that I am trying with CTB ant this functions is for STB.

 

Is there any way to do that with CTB?

Message 11 of 12
DannyNL
in reply to: gustavobernardi

If you only want to set the CTB for the Model (or any other) layout, you need to use the Layout object.

 

The code below will give you the CTB for the current layout in the drawing.

If the value is an empty string "" then it is set to 'None'.

 

(setq CurDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(vla-get-StyleSheet (vla-get-ActiveLayout CurDoc))

 

Use this to directly get the value for the StyleSheet property for any layout without worrying if it's the current one or not

 

(vla-get-StyleSheet (vla-item (vla-get-Layouts CurDoc) "NameOfLayout"))

;;; example
(vla-get-StyleSheet (vla-item (vla-get-Layouts CurDoc) "Model"))

To set the CTB use 'put' instead of 'set' like the code below.

Make sure the CTB name provided exists otherwise you will get an error.

 

(vla-put-StyleSheet (vla-item (vla-get-Layouts CurDoc) "Model") "acad.ctb")

;;; or even better with error trapping
(vl-catch-all-apply 'vla-put-StyleSheet (list (vla-item (vla-get-Layouts CurDoc) "Model") "acad.ctb"))

To get a list of available plot styles (CTB & STB) use the GetPlotStyleTableNames on any of the layout objects.

This can be used to check if the CTB exists prior to trying to set the StyleSheet property.

 


(vlax-safearray->list (vlax-variant-value (vla-GetPlotStyleTableNames (vla-get-ActiveLayout CurDoc))))
Message 12 of 12
gustavobernardi
in reply to: DannyNL

Fantastic. Here is the final Code:

 

(defun c:set-ps()
(vl-load-com)
(setq CurDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(setq installed_ps(vlax-safearray->list (vlax-variant-value (vla-GetPlotStyleTableNames (vla-get-ActiveLayout CurDoc)))));;get the plotstyles
(if (= (vl-position "Ringo 1-50.ctb" installed_ps)nil)(c:penasringo));;verify if the plotstyle exist, if not - install
(setq cur_ps(vla-get-StyleSheet (vla-item (vla-get-Layouts CurDoc) "Model")));;get the actual plotstyle
(if (= cur_ps "")(vl-catch-all-apply 'vla-put-StyleSheet (list (vla-item (vla-get-Layouts CurDoc) "Model") "Ringo 1-50.ctb")));;if the user don't choose put the plotstyle
)

 

Thank you!

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

Post to forums  

Autodesk Design & Make Report

”Boost