TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: qjchen on June 15, 2008, 06:17:08 AM

Title: How to change all the width of the lwpolyline in many block.
Post by: qjchen on June 15, 2008, 06:17:08 AM
There are many lwpolyline in many block, I need to change all the polyline width to a new one, just like "30".

I'm unfamiliar with sub entity, could you help me? Thank you very much.

 :-D
Title: Re: How to change all the width of the lwpolyline in many block.
Post by: DEVITG on June 15, 2008, 06:53:16 PM
There are many lwpolyline in many block, I need to change all the polyline width to a new one, just like "30".

I'm unfamiliar with sub entity, could you help me? Thank you very much.

 :-D


Can you upload the dwg .??
Title: Re: How to change all the width of the lwpolyline in many block.
Post by: FengK on June 15, 2008, 10:30:04 PM
There are many lwpolyline in many block, I need to change all the polyline width to a new one, just like "30".

I'm unfamiliar with sub entity, could you help me? Thank you very much.

 :-D


block definition is like a collection, so you can use vlax-for to loop through the  subentities. say you have a block named "BlkName1" and doc is the document object:

Code: [Select]
(setq colBlk (vla-get-blocks doc)
      blkdef (vla-item colBlk "BlkName1")
)
(vlax-for obj blkDef
  (if (eq (vla-get-objectname obj) "AcDbPolyline"))
  (vla-put-width obj 30)
)













Title: Re: How to change all the width of the lwpolyline in many block.
Post by: Kerry on June 16, 2008, 01:14:09 AM

yuanqiu ,

The code Kelie posted should be fine for block instances.
... or do you want to change the original block definition in the BlockDefinitionTable as well ??
Title: Re: How to change all the width of the lwpolyline in many block.
Post by: qjchen on June 17, 2008, 09:51:40 AM
To DEVITG
Now I have no such file, I will try to upload it later.

To Kelie
Your code will help me greatly, I think this must be the right and quick way to solve the question.

To Kerry Brown
I dont need to change the original block definition in the BlockDefinitionTable:)

Thank you all very much!

Title: Re: How to change all the width of the lwpolyline in many block.
Post by: ElpanovEvgeniy on July 24, 2008, 07:29:14 AM
Code: [Select]
(defun c:test (/ s)
 (vl-load-com)
 (princ "\n Select the block with a polyline")
 (if (and (setq s (ssget "_+.:S" '((0 . "insert"))))
          (setq s (cdr (assoc 2 (entget (ssname s 0)))))
     ) ;_  and
  (progn
   (vlax-for
            o
            (vla-item (vla-get-blocks
                       (vla-get-ActiveDocument (vlax-get-acad-object))
                      ) ;_  vla-get-blocks
                      s
            ) ;_  vla-item
    ;;(setq o (vla-item (vla-item (vla-get-blocks (vla-get-ActiveDocument(vlax-get-acad-object))) s)0))
    (if (= (vla-get-objectname o) "AcDbPolyline")
     (vl-catch-all-apply 'vla-put-ConstantWidth (list o 30.))
    ) ;_  if
   ) ;_  vlax-for
   (foreach x (mapcar (function cadr)
                      (ssnamex (ssget "_x" (list (cons 2 s))))
              ) ;_  mapcar
    (vla-update (vlax-ename->vla-object x))
   ) ;_  foreach
  ) ;_  progn
 ) ;_  if
 (princ)
)
Title: Re: How to change all the width of the lwpolyline in many block.
Post by: qjchen on July 24, 2008, 08:22:28 AM
Thank you, Evgeniy, it do work.
Thx.