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

Change Polyline Global Width of selected blocks

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
nina.susanu
3046 Views, 14 Replies

Change Polyline Global Width of selected blocks

Hi there,

I have a drawings with tens of blocks in it. I'd like to be able to change the polylines global width within certain blocks by selecting witch one to be changed and specify the new dimension. I'd like to be able to have different width for same name blocks.

I'm not sure if this is possible. 

Many thanks for your time!

14 REPLIES 14
Message 2 of 15
john.uhden
in reply to: nina.susanu

I don't think it's possible to have varying widths for the same named block, but then I have no experience with dynamic blocks.  A workaround might be to clone the block definition by a different name.  I have never done it, but feel that it is possible.  Are anonymous blocks permitted?

Other than that, yes it can be done with AutoLisp.

John F. Uhden

Message 3 of 15
nina.susanu
in reply to: john.uhden

I tried yesterday some methods and yes, I couldn't change polylines widths with different values for same name block. Seems that I would need to do dynamic block for each sequence of global width. 

Thank you

Message 4 of 15
Moshe-A
in reply to: nina.susanu

Nina,

 

 

it's true the only way to achieve this is Dynamic Block and one of the option to do it is Visibility States

you have to copy the polylines multiple times as width needed and hope your width list is fixed and limited.

 

Moshe

 

Message 5 of 15
Kent1Cooper
in reply to: nina.susanu

Do you use color-based pen assignments for lineweights in Plotting, and is the range of widths you want within the range of color-based lineweights used?  If so, I would do this:

1)  Give the Polyline in the Block's definition a color of BYBLOCK.

 

2)  Give each Insertion of the Block a color assignment, resulting in that Polyline being of the color that will Plot at the desired width.

 

Only one Block definition required, and not a dynamic one, so the approach can be used in pre-dynamic-Block versions.

Kent Cooper, AIA
Message 6 of 15
nina.susanu
in reply to: Kent1Cooper

I never thought to that. It's not a bad idea but I have to insert lots of blocks with same color and global width visibility is a must in  the drawing. Anyway, I have already started to create dynamic blocks with visibility states. It will take forever but for the moment is the best option I have.

 

Thank you all for your help

Message 7 of 15
Kent1Cooper
in reply to: nina.susanu


@nina.susanu wrote:

.... I have to insert lots of blocks with same color and global width visibility is a must in  the drawing. ....


 

Then how about leaving the color of the Polyline as ByLayer [or any other color you like], but giving it a lineweight  of ByBlock?  Turn on the LWDISPLAY System Variable to show lineweights, or in the Status bar:

ShowLineweight.png

and give each Block insertion a lineweight override of the weight you want that Polyline to have in that Block insertion.  Same color, same [non-dynamic] Block, different weights:
ShowLineweight2.png

Kent Cooper, AIA
Message 8 of 15
nina.susanu
in reply to: Kent1Cooper

A really good idea. I should try and see if it's working with dynamic block salso because the blocks I have are dynamics. Anyway, it's good to take in consideration as a non complicated solution. 

Many thanks.

Message 9 of 15

Going back to this old post, I was wondering if a lisp could solve this issue, for example, to manually select certain blocks inside a model space and change the width of the polylines inside with a certain value.

I found this Lee Mac lisp, where he changes the width of all objects including blocks, which I tried and works fine. Although, I understand how he has done it, my knowledge regarding Autolisp is none, so I can't find myself a solution just to select some blocks and apply the changes to those, disregarding all the other objects, and apply the changes just to selections. 

 

(defun c:test (/ *error* wid uFlag)
(vl-load-com)
;; Lee Mac ~ 15.01.10

(defun *error* (msg)
(and uFlag (vla-EndUndoMark doc))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ))

(setq doc (cond (doc) ((vla-get-ActiveDocument
(vlax-get-acad-object)))))

(initget 4)
(setq wid (cond ((getdist "\nSpecify New Width <0.0> : ")) (0.0)))
(setq uFlag (not (vla-StartUndoMark doc)))

(vlax-for blk (vla-get-Blocks doc)

(vlax-for obj blk

(if (eq "AcDbPolyline" (vla-get-Objectname obj))
(vla-put-ConstantWidth obj wid))))

(setq uFlag (vla-EndUndoMark doc))
(vla-regen doc acActiveViewport)
(princ))

 

Message 10 of 15

@bulinaninabulina 

I am dismayed (actually worse but I can't write it).  My previous attempt at posting failed, and I am not writing all the verbiage again.

But here is some code that should work for you:

(defun c:NPW (/ *error* ss i bname bnames blks wid uFlag)
(vl-load-com)
;; Lee Mac ~ 15.01.10
;; Altered by John Uhden (1-27-23) to modify only selected blocks
(princ "\nNPW (Nested Polyline Width, John Uhden 1-27-2023)")
(princ "\nAdaped from Lee Mac code of 1-15-2010")
(setq ok 0)
(defun *error* (msg)
  (mapcar 'setvar vars vals)
  (vla-EndUndoMark doc)
  (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
    (princ (strcat "\n** Error: " msg " **"))
  )
  (princ)
)
(setq vars '("cmdecho"))
(setq vals (mapcar 'getvar vars))
(setvar "cmdecho" 0)
(command "_.expert" (getvar "expert")) ;; dummy command
(setq doc (cond (doc) ((vla-get-ActiveDocument (vlax-get-acad-object)))))
(alert "You will be allowed to select\nonly block references.")
(setq ss (ssget '((0 . "INSERT"))))
(repeat (setq i (sslength ss))
   (setq e (ssname ss (setq i (1- i))))
   (setq bname (cdr (assoc 2 (entget e))))
   (if (not (vl-position bname bnames))(setq bnames (cons bname bnames)))
)
(setq ok 1)
(initget 4)
(setq wid (cond ((getdist "\nSpecify New Width <0.0> : ")) (0.0)))
(vla-EndUndoMark doc)  ;; end any previously set undo.
(setq uFlag (not (vla-StartUndoMark doc)))
(setq ok 2)
(setq blks (vla-get-blocks doc))
(foreach bname bnames
  (setq blk (vla-item blks bname))
  (vlax-for obj blk
    (if (eq "AcDbPolyline" (vla-get-Objectname obj))
      (vla-put-ConstantWidth obj wid)
    )
  )
)
(setq ok 3)
(setq uFlag (vla-EndUndoMark doc))
(vla-regen doc acActiveViewport)
(princ)
)

 

 

John F. Uhden

Message 11 of 15

 @john.uhden 

 

Hi John, 

 

Your code works just fine. I did start to read some tutorials for lisp last night just to be able to understand lisp and what Lee did and how. Now I've got more research to do to be able to fully read yours.

I really appreciate your quick answer and the solution. 

Don't want to stretch my luck with you, but is that possible to modify the lisp above, as when I've got for example 5 instances of the same named block in the same DWG file, to change the value of each pline to be different, without the need of renaming each block?  

 

Many thanks again for your time!

Message 12 of 15

@bulinaninabulina wrote, "... is that possible to modify the lisp above, as when I've got for example 5 instances of the same named block in the same DWG file, to change the value of each pline to be different, without the need of renaming each block?"

No.  My response that got cancelled explained that.  Each and every insertion of a standard block references the same block definition.  You are correct in surmising that we would have to make separate copies of the definition with different names.  I know of only one lengthy way to do that unless each of your blocks were anonymously named.  AutoCAD does that automatically such as "*U1" "*U2" etc.  Otherwise you will have to come up with a block naming convention using suffixes like "MyBlock-1" "MyBlock-2" etc.  The code could easily determine the next available suffix and make it the default.

Maybe someone here who knows dynamic blocks can offer a better answer.  @Kent1Cooper , @hak-vz, @BeeKee-CZ @ronjonp ?

John F. Uhden

Message 13 of 15


@bulinaninabulina wrote:

... is that possible to modify the lisp above, as when I've got for example 5 instances of the same named block in the same DWG file, to change the value of each pline to be different, without the need of renaming each block?....


Not by Polyline width, but would the lineweight of ByBlock as in Message 7 work for you?  The code could presumably be modified to assign ByBlock lineweight to the Polyline(s).

Kent Cooper, AIA
Message 14 of 15
john.uhden
in reply to: Kent1Cooper

@Kent1Cooper 

I don't remember this fellow, but his response is interesting...

 

   
in reply to: ACTON
 

John F. Uhden

Message 15 of 15

@john.uhden  @Kent1Cooper 

Hi guys, I really appreciate your help. Got some new things to think about now, and some ideas for changing some of my processes.

 

John, I can see your point of view. For now, I think I can work out with renaming the dynamic blocks after insertion as seems the simplest solution as most of the time the number of the same block won't exceed 5 or so.

 

Kent, I did try with the line weight which is not a bad idea but is not working for what I need, because even though initially is just for visual purposes, in the end, I get to use the values of the global width extraction and linked to formulas in xls files, and will complicate the extraction process. 

 

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

Post to forums  

Forma Design Contest


AutoCAD Beta