Set VP Linenweight in LSP

Set VP Linenweight in LSP

eamon.fleming
Contributor Contributor
1,221 Views
15 Replies
Message 1 of 16

Set VP Linenweight in LSP

eamon.fleming
Contributor
Contributor

Hi guys I have been cobbling together a program to set lineweight to colors automatically so I can update hundreds of prototypes.

What I have so far is working fine for the lineweight but I was wondering if it is possible to set VP lineweights at the same time using a similar method

 

(defun c:assignlineweights ( / layers_col col)
 (SETVAR "lwunits" 1 )
  (vl-load-com)
  (or *acaddoc* (setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))))
  (setq layers_col (vla-get-layers *acaddoc*))
  (vlax-for item layers_col
    (setq col (vlax-get-property item 'color))
    (cond ((= col 1)(vlax-put-property item 'LineWeight acLnWt025))
             ((= col 2)(vlax-put-property item 'LineWeight acLnWt120))
             ((= col 3)(vlax-put-property item 'LineWeight acLnWt035));copy down and change to suit

)
  )
  (SETVAR "lwunits" 0 )
  (PRINC "Assign Lineweights to Layers loaded.  Type assignlineweights to run.")
(princ)
)

 

I can't seem to find a variable or property like acLnWt  but for VP Lineweight

Thanks to he guys whose code I poached already

 

Any help would be greatly appriciated

 

Eamon

0 Likes
Accepted solutions (2)
1,222 Views
15 Replies
Replies (15)
Message 2 of 16

wispoxy
Advisor
Advisor

@eamon.fleming Intergrate this code into your current lisp. It should prompt you for a lineweight and has a high rating, make sure to preset the vp on its own layer or other lines will be effected also.

 

I got the code from Lee Mac Forums, its creator is unknown. The code is really for lines by layer.

 

(defun c:LWChange ( / lws lw n )

(setq lws
'(-3.00 0.00 0.05 0.09 0.13 0.15 0.18 0.20 0.25 0.30 0.35 0.40 0.50
0.53 0.60 0.70 0.80 0.90 1.00 1.06 1.20 1.40 1.58 2.00 2.11
)
)

(while
(and
(setq lw (getreal "\nSpecify Lineweight (-3 for Default): "))
(not (member lw lws))
)
(princ "\n--> Invalid Lineweight.")
)
(if lw
(progn
(setq lw (if (<= 0 lw) (fix (* 100 lw)) (fix lw)))
(vlax-for l (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))
(if
(and
(wcmatch (setq n (strcase (vla-get-name l))) "*FURN*,*EQPM*,*PFIX*")
(not (wcmatch n "MV-*EQPM*"))
)
(vla-put-lineweight l lw)
)
)
)
)
(princ)

)
(vl-load-com) (princ)

Message 3 of 16

eamon.fleming
Contributor
Contributor
Thanks Andrew I will check this out this afternoon

Eamon
0 Likes
Message 4 of 16

eamon.fleming
Contributor
Contributor

Hi Andrew I looked at the code & gave it a test run & I am not sure what it does?
I am trying to set the VP Lineweight of layers based on the color of the layer, see the image below

 

vplineweight.jpg

if the Lineweight is 0.70mm I want to set the VP Lineweight to 0.35mm (1/2 scale)

The code I have works for the lineweight but I don't know the variable for VP lineweight 😞

I have given up on the help in autocad as you can't browse any more, you pretty much need to know what you want to search for.

 

Thanks in advance

 

Eamon

0 Likes
Message 5 of 16

hmsilva
Mentor
Mentor

@eamon.fleming wrote:

Hi guys I have been cobbling together a program to set lineweight to colors automatically so I can update hundreds of prototypes.

What I have so far is working fine for the lineweight but I was wondering if it is possible to set VP lineweights at the same time using a similar method

 

(defun c:assignlineweights ( / layers_col col)
 (SETVAR "lwunits" 1 )
  (vl-load-com)
  (or *acaddoc* (setq *acaddoc* (vla-get-activedocument (vlax-get-acad-object))))
  (setq layers_col (vla-get-layers *acaddoc*))
  (vlax-for item layers_col
    (setq col (vlax-get-property item 'color))
    (cond ((= col 1)(vlax-put-property item 'LineWeight acLnWt025))
             ((= col 2)(vlax-put-property item 'LineWeight acLnWt120))
             ((= col 3)(vlax-put-property item 'LineWeight acLnWt035));copy down and change to suit

)
  )
  (SETVAR "lwunits" 0 )
  (PRINC "Assign Lineweights to Layers loaded.  Type assignlineweights to run.")
(princ)
)

 

I can't seem to find a variable or property like acLnWt  but for VP Lineweight

Thanks to he guys whose code I poached already

 

Any help would be greatly appriciated

 

Eamon


Hi Eamon,

there is no property for VPLineweight...

 

Lineweight in a viewport( and all overrides properties except layer visibility overrides)  is stored as dictionary data in layer extension dictionarie, and the Xrecord name is ADSK_XREC_LAYER_LINEWT_OVR

 

If you are not familiar with dictionaries, probably it will be easier, to set current each viewport and use the -vplayer command...

 

Hope this helps,
Henrique

 

 

EESignature

Message 6 of 16

eamon.fleming
Contributor
Contributor
Thanks Henrique, I know nothing about dictionaries so I will look into the vplayer command

Eamon
0 Likes
Message 7 of 16

hmsilva
Mentor
Mentor
Accepted solution

@eamon.fleming wrote:
Thanks Henrique, I know nothing about dictionaries so I will look into the vplayer command

Eamon

You're welcome, Eamon!

As a starting point, a quick and dirty 'demo'...

 

(defun c:demo (/ ctab ent lay lst lw name)
    (while (setq lay (tblnext "LAYER" (null lay)))
        (setq name (cdr (assoc 2 lay))
              ent  (entget (tblobjname "LAYER" name))
              lw   (cdr (assoc 370 ent))
        )
        (if (> lw 0.0)
            (progn
                (setq lw (/ lw 200.0))
                (if (assoc lw lst)
                    (setq lst (subst (cons lw (strcat (cdr (assoc lw lst)) "," name)) (assoc lw lst) lst))
                    (setq lst (cons (cons lw name) lst))
                )
                (setq ctab (getvar 'ctab))
                (foreach layt (layoutlist)
                    (setvar 'ctab layt)
                    (command "vplayer")
                    (foreach x lst
                        (command "LW" (car x) (cdr x) "_All")
                    )
                    (command "")
                )
                (setvar 'ctab ctab)
            )
        )
    )
    (princ)
)


Hope this helps,
Henrique

 

EESignature

Message 8 of 16

eamon.fleming
Contributor
Contributor
Thanks Henrique I will look at this tomorrow & see how I make out

Eamon
0 Likes
Message 9 of 16

wispoxy
Advisor
Advisor

@eamon.fleming Glad to see your problem was resolved.

 

@hmsilva Well done!

0 Likes
Message 10 of 16

hmsilva
Mentor
Mentor

@Anonymous wrote:

...

@hmsilva Well done!


Thank you, wisp!

 

Henrique

EESignature

0 Likes
Message 11 of 16

eamon.fleming
Contributor
Contributor

Hi Hernrique I finally got some time to play with this demo & seems to be setting the VP lineweights but it sets the first layer/color to 0.024" then all the rest to 0.083" ? I am having trouble deciphering the code to see where the 0.083" is being set? is it the LW variable?

 

Thanks in advance

 

Eamon

0 Likes
Message 12 of 16

hmsilva
Mentor
Mentor

@eamon.fleming wrote:

Hi Hernrique I finally got some time to play with this demo & seems to be setting the VP lineweights but it sets the first layer/color to 0.024" then all the rest to 0.083" ? I am having trouble deciphering the code to see where the 0.083" is being set? is it the LW variable?

 

Thanks in advance

 

Eamon


Hi Eamon,

I do not have AutoCAD in this laptop, if possible, post a sample dwg, and tonight I'll see what I can do...

 

Henrique

EESignature

0 Likes
Message 13 of 16

eamon.fleming
Contributor
Contributor

Hi Henrique thanks for the fast responce. I have attached a simple sample drawing that I ran my program on to set the lineweights per color thenI ran demo to set the VPlineweight

 

This drawing is typical of most of our templates in that the model space viewport in the layout is scaled to 1:2

 

In a perfect world I would like demo to see what the lineweight is per layer then divide it by 2 to set the VPlineweight

 

Thanks

 

Eamon

0 Likes
Message 14 of 16

hmsilva
Mentor
Mentor
Accepted solution

Eamon,

tested in a borrowed  PC, without error....

Lineweight.PNG

 

Henrique

EESignature

Message 15 of 16

eamon.fleming
Contributor
Contributor

Hi Henrique that is great, I notice that the lineweights are in mm, is that the problem with mine that I have them set to inches?

 

OK I just set the lineweight units to mm & it works! thanks Henrique

 

Eamon

0 Likes
Message 16 of 16

hmsilva
Mentor
Mentor

@eamon.fleming wrote:

Hi Henrique that is great, I notice that the lineweights are in mm, is that the problem with mine that I have them set to inches?

 

OK I just set the lineweight units to mm & it works! thanks Henrique

 

Eamon


Eamon,

sorry, but feet and inches are not my world, I'm a metric guy.


Glad I could help!
Henrique

EESignature