TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on December 04, 2004, 01:46:34 PM

Title: Plot Style from a Layer ??
Post by: CAB on December 04, 2004, 01:46:34 PM
I'm looking for a way to get the Plot Style of a layer in the drawing using plain lisp.
Any ideas?
Title: Plot Style from a Layer ??
Post by: Jeff_M on December 04, 2004, 02:42:38 PM
Here's my idea, from the help file on Layer Table objects:
390 Hard pointer ID/handle of PlotStyleName object
So:
Code: [Select]
(setq layEnt (entget (tblobjname "layer" "0")))
(setq pltStyl (entget (cdr (assoc 390 layEnt))))
Title: Plot Style from a Layer ??
Post by: Keith™ on December 04, 2004, 02:55:23 PM
Jeff that is exactly what I was going to suggest, but it does not work unless you are plotting by layer rather than by entity lineweight or color
Title: Plot Style from a Layer ??
Post by: CAB on December 04, 2004, 03:00:39 PM
I got this on the web:
Code: [Select]
(vl-load-com)
(setq doc   (vla-get-activedocument(vlax-get-acad-object))
      layobj(vla-item(vla-get-layers doc) "MyLayer"))
(if layobj
  (setq style (vla-get-plotstylename layobj))
)

But didn't see a way to do it in plain lisp.
Title: Plot Style from a Layer ??
Post by: Keith™ on December 04, 2004, 03:19:23 PM
I just tried it and evidently there is some serious issues with the online documentation.

The DXF 390 is supposed to point to the plotstyle object and give the handle of the plotstyle itself, along with the description.
Title: Plot Style from a Layer ??
Post by: Jeff_M on December 04, 2004, 03:27:59 PM
Quote from: Keith
....unless you are plotting by layer rather than by entity lineweight or color

Isn't that what he'd be looking for then? You don't have a plot style for a layer unless you are plotting with plot styles vs color-dependent styles.....

In the LayerManager dilalog when CTB's are used, the PlotStyle is greyed out and the layer's color is displayed.

So you could do this: modified after some testing.....
Code: [Select]

(setq layEnt (entget (tblobjname "layer" "0")))
(if (= 0 (getvar "pstylemode"))
  (progn
    (setq pltStyl (cdr (assoc 3 (entget (cdr (assoc 330 (entget (cdr (assoc 390 layEnt)))))))))
    )
  (progn
    (setq pltStyl (strcat "Color_" (itoa (cdr (assoc 62 layEnt)))))
    )
  )

Or am I way off since I don't use NamedPlotStyles?
Title: Plot Style from a Layer ??
Post by: Keith™ on December 04, 2004, 03:35:30 PM
that might work indeed
Title: Plot Style from a Layer ??
Post by: CAB on December 04, 2004, 03:36:01 PM
Jeff,
Thanks for the help..

This is what I get from PltStyl
Code: [Select]
((-1 . <Entity name: 1bb3930>)
  (0 . "ACDBPLACEHOLDER")
  (5 . "26")
  (102 . "{ACAD_REACTORS")
  (330 . <Entity name: 1bb3830>)
  (102 . "}")
  (330 . <Entity name: 1bb3830>)
)
Title: Plot Style from a Layer ??
Post by: CAB on December 04, 2004, 03:38:34 PM
Oooooh the old edit trick :)

That did it.
Thanks Jeff :D
Title: Plot Style from a Layer ??
Post by: Jeff_M on December 04, 2004, 03:38:34 PM
Removed stuff that CAB had already found......

You're welcome  :mrgreen:
Title: Plot Style from a Layer ??
Post by: CAB on December 04, 2004, 03:46:01 PM
Wait a second... :shock:

that code returns where all the plot style names are stored. So it only
returns the first dxf code 3 it finds.

Code: [Select]
_$ (assoc 390 layEnt)
(390 . <Entity name: 1bb3930>)
_$
((-1 . <Entity name: 1bb3930>)
  (0 . "ACDBPLACEHOLDER")
  (5 . "26")
  (102 . "{ACAD_REACTORS")
  (330 . <Entity name: 1bb3830>)
  (102 . "}")
  (330 . <Entity name: 1bb3830>)
)
_$
((-1 . <Entity name: 1bb3830>)
  (0 . "ACDBDICTIONARYWDFLT")
  (5 . "6")
  (102 . "{ACAD_REACTORS")
  (330 . <Entity name: 1bb3838>)
  (102 . "}")
  (330 . <Entity name: 1bb3838>)
  (100 . "AcDbDictionary")
  (280 . 0)
  (281 . 1)
  (3 . "Heavy")
  (350 . <Entity name: 1bb3ba0>)
  (3 . "Light")
  (350 . <Entity name: 1bb3930>)
  (3 . "Medium")
  (350 . <Entity name: 1bb3a98>)
  (3 . "Normal")
  (350 . <Entity name: 1bb3828>)
  (3 . "vHeavy")
  (350 . <Entity name: 1bb3ba8>)
  (3 . "XHeavy")
  (350 . <Entity name: 1bb3aa0>)
  (3 . "xL_Scrn")
  (350 . <Entity name: 1bb6548>)
  (3 . "xLight")
  (350 . <Entity name: 1bb3ad8>)
  (3 . "xxLight")
  (350 . <Entity name: 1bb6550>)
  (100 . "AcDbDictionaryWithDefault")
  (340 . <Entity name: 1bb3828>)
)
Title: Plot Style from a Layer ??
Post by: Jeff_M on December 04, 2004, 03:59:11 PM
I know, I know.......brb   That's what happens when I try it in a test drawing with only 1 layer & 1 plotstyle......
Title: Plot Style from a Layer ??
Post by: Jeff_M on December 04, 2004, 04:04:46 PM
This should do it:
Code: [Select]

(if (= 0 (getvar "pstylemode"))
  (progn
    (setq pltStylTbl (entget (cdr (assoc 330 (entget (cdr (assoc 390 layEnt)))))))
    (setq pos (vl-position (cons 350 (cdr (assoc 390 layEnt))) pltstyltbl))
    (setq pltStyl (cdr (nth (1- pos) pltstyltbl)))
    )
  (progn
    (setq pltStyl (strcat "Color_" (itoa (cdr (assoc 62 layEnt)))))
    )
  )
Title: Plot Style from a Layer ??
Post by: CAB on December 04, 2004, 04:08:18 PM
Hey you beat me to it.. Good job.

Code: [Select]
(defun c:test ()
  (setq layent (entget (tblobjname "layer" "0")))
  (setq pltstyldict (entget (cdr (assoc 330 (entget (cdr (assoc 390 layent)))))))
  (if (setq tmp (member (cons 350 (cdr (assoc 390 layent))) (reverse pltstyldict)))
    (setq pltsty (cdr (assoc 3 tmp)))
  )
)
Title: Plot Style from a Layer ??
Post by: Jeff_M on December 04, 2004, 04:10:03 PM
And with standard lisp, change my (setq pos...) line to this:
(setq pos (- (length pltstyltbl) (length (member (cons 350 (cdr (assoc 390 layEnt))) pltstyltbl))))
Title: Re: Plot Style from a Layer ??
Post by: Peter2 on June 21, 2016, 04:53:30 AM
Warning: this topic has not been posted in for at least 120 days. 12 years.
Nevertheless - just found it and it is helpful for me. Thank you   :-D