Author Topic: Region  (Read 3188 times)

0 Members and 1 Guest are viewing this topic.

ImaJayhawk

  • Guest
Region
« on: September 16, 2004, 05:02:00 PM »
If I've got a selection set of LWPolylines and have converted them to vla-objects, what is a good way to change the LWPolylines into Regions.


Code: [Select]

(foreach bos ss
    (if (= "AcDbPolyline" (vlax-get-property bos 'objectname))
..........


Thanks.


--ImaJayhawk

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Region
« Reply #1 on: September 16, 2004, 05:13:08 PM »
I'm guessing that "ss" is not a selection set but rather a list of vla-objects....
If so, this should do it:
Code: [Select]

(foreach bos ss
  ;; assumes that "space" is set to the vla-object of the space that the plines are in
  ;; eg: (setq space (vla-get-modelspace *doc*))

  (setq new-region (vlax-invoke space "addregion" (list bos)))
  ;; do whatever you want with this region..layer, color, etc.
);next

SMadsen

  • Guest
Region
« Reply #2 on: September 16, 2004, 05:29:06 PM »
Just cooked up the example below while Jeff replied and didn't want it to go to vaste.

It's worth noticing, though, that VLAX-INVOKE works with most native AutoLISP data types - such as the list in Jeff's example - while VLAX-INVOKE-METHOD and the VLA-xxx functions don't. Hence the safearray below.

Code: [Select]
(defun pl2reg (/ ss a obj objarray ms)
  (vl-load-com)
  (cond ((setq ss (ssget '((0 . "LWPOLYLINE"))))
         (setq a        0
               objarray (vlax-make-safearray vlax-vbObject '(0 . 0))
               ms       (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))
         )
         (repeat (sslength ss)
           (setq obj (vlax-ename->vla-object (ssname ss a))
                 a   (1+ a))
           (vlax-safearray-fill objarray (list obj))
           (vla-addregion ms objarray)
         )
        )
  )
)

ImaJayhawk

  • Guest
Region
« Reply #3 on: September 16, 2004, 06:04:28 PM »
Thanks that's what I needed.  Although I had to read the example using safearrays several times.... :shock:




--ImaJayhawk

Jeff_M

  • King Gator
  • Posts: 4094
  • C3D user & customizer
Region
« Reply #4 on: September 16, 2004, 06:35:18 PM »
Quote from: ImaJayhawk
... had to read the example using safearrays several times.... :shock:

Which is why I avoid them as much as possible by using vlax-get, vlax-put & vlax-invoke. There are a few methods/properties I've found that don't work properly this way, but they are so few that I usually don't remember which ones until I try to use it.