gS7 Posted March 15, 2013 Posted March 15, 2013 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)) ) Quote
Stefan BMR Posted March 15, 2013 Posted March 15, 2013 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) ) Quote
gS7 Posted March 15, 2013 Author Posted March 15, 2013 Perfectly Superb !! Thanks a lot Stefan BMR Quote
Lee Mac Posted March 15, 2013 Posted March 15, 2013 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) 1 Quote
gS7 Posted March 15, 2013 Author Posted March 15, 2013 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)) Quote
Lee Mac Posted March 15, 2013 Posted March 15, 2013 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) 2 Quote
gS7 Posted March 16, 2013 Author Posted March 16, 2013 Sorry for late reply Lee .. Thank again for codes Quote
aazaaz Posted September 23, 2021 Posted September 23, 2021 > 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? Quote
aazaaz Posted September 23, 2021 Posted September 23, 2021 (edited) > Lee MAC Thank you. Edited September 23, 2021 by aazaaz Quote
Recommended Posts
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.