Jump to content

Recommended Posts

Posted

Hello Cad Tutor Good Moring

 

I Need Clarification about VLA-ADDREGION FUntion

 

(vla-addregion object)

 

please tel me which object i must select

 

(defun c:test()
 (setq obj (vlax-ename->vla-object (car (entsel))))
 (setq reg (vla-addregion obj))
)

Posted

Obj must be an array of acad entities. Selected objects must form a valid shape, i.e. not selfintersectiong contour, connected ends etc.

(defun ad_region (ss / ms i l array)
 (setq ms (vla-get-ModelSpace
            (vla-get-ActiveDocument
              (vlax-get-acad-object))))
 (repeat (setq i (sslength ss))
   (setq l (cons (vlax-ename->vla-object  (ssname ss (setq i (1- i)))) l))
   )
 (setq array (vlax-safearray-fill (vlax-make-safearray vlax-vbObject (cons 0 (1- (length l)))) l))
 (vl-catch-all-apply 'vla-AddRegion (list ms array))
 )

(defun C:MY_REG (/ ss)
   (if (setq ss (ssget)) (ad_region ss))
   (princ)
 )

Posted

Perfectly Superb !!

 

Thanks a lot Stefan BMR :D

Posted

You can alternatively use the undocumented vlax-invoke function to avoid the conversion of the object array argument to a variant:

(defun c:addregion ( / i l s )
   (if (setq s (ssget '((410 . "Model"))))
       (progn
           (repeat (setq i (sslength s))
               (setq l (cons (vlax-ename->vla-object (ssname s (setq i (1- i)))) l))
           )
           (vlax-invoke (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))) 'addregion l)
       )
   )
)
(vl-load-com)

  • Like 1
Posted

Lee Mac

 

Suppose for Single Entity Selection Can i Use This Method ? is this right method ?

(defun c:Reg ( / s adoc space)
   (vl-load-com)
   (if (and (setq s (car (entsel "\nSelect Object:")))
         (eq (cdr (assoc 410 (entget s))) "Model")
    )
	(progn
	    (setq obj (vlax-ename->vla-object s))
	    (setq adoc(vla-get-activedocument (vlax-get-acad-object)))
		(setq space (vla-get-modelspace adoc))
		(vlax-invoke space 'addregion (list obj))
	)
)
(princ))

Posted
Suppose for Single Entity Selection Can i Use This Method ? is this right method ?

 

Yes, that would work for objects residing in Modelspace.

 

Though, as Stefan has noted above, be aware that the program will error with objects which do not meet the criteria for a region, so you may wish to include some error trapping to either prevent the user from selecting invalid objects, or a vl-catch-all-apply expression as used by Stefan to catch the error should an invalid object be selected.

 

For objects residing in any space, consider the following method:

(defun c:reg ( / doc ent obj )
   (if (setq ent (car (entsel)))
       (progn
           (setq obj (vlax-ename->vla-object ent)
                 doc (vla-get-activedocument (vlax-get-acad-object))
           )
           (vlax-invoke
               (if (vlax-method-applicable-p doc 'objectidtoobject32)
                   (vla-objectidtoobject32 doc (vla-get-ownerid32 obj))
                   (vla-objectidtoobject   doc (vla-get-ownerid   obj))
               )
               'addregion (list obj)
           )
       )
   )
   (princ)
)
(vl-load-com)

  • Like 2
Posted

Sorry for late reply Lee ..

 

Thank again for codes

  • 8 years later...
Posted

> Lee Mac

 

How in Your last code to consider (to provide) hit in a set of the self-crossed (self intersections) flat objects and to prevent emergency termination of work of the code?

Posted (edited)

> Lee MAC

Thank you.

Edited by aazaaz

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...