Invalid input error when trying to use vlax-get 'centroid on {ACAD_XDICTIONARY

Invalid input error when trying to use vlax-get 'centroid on {ACAD_XDICTIONARY

Anonymous
Not applicable
1,468 Views
4 Replies
Message 1 of 5

Invalid input error when trying to use vlax-get 'centroid on {ACAD_XDICTIONARY

Anonymous
Not applicable

Hello!

I'm facing a problem to determine objects centroid when a  non-graphical objects: dictionary is attached to an entity. 

How to fix it?

 

Check attached .dwg (I could not save it as 2013 version file because of the custom objects that are not supported)

                     and .lst function (I'm using C:test of 

 

(entget ent4) returns

((-1 . <Entity name: 29e2dc272c0>) (0 . "LWPOLYLINE") (5 . "248DC") (102 . "{ACAD_XDICTIONARY") (360 . <Entity name: 29e2dc26660>) (102 . "}") (330 . <Entity name: 29e3d8931f0>) (100 . "AcDbEntity") (67 . 0) (410 . "Model") (8 . "Edificacoes") (100 . "AcDbPolyline") (90 . 12) (70 . 1) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 476875.0 6.67724e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476872.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476870.0 6.67724e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476875.0 6.67724e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476888.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476886.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476882.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476882.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476878.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476880.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476875.0 6.67724e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 476872.0 6.67725e+06) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0))

 

Thanks in advance + regards,

Lzucco

0 Likes
Accepted solutions (1)
1,469 Views
4 Replies
Replies (4)
Message 2 of 5

dlanorh
Advisor
Advisor

The centroid property only applies to 3dsolids and regions. However you can use the closed polyline to make a region.

(defun rh:centroid ( obj ms / obj_arr reg_obj c_pt rtn)
  (setq rtn nil)
  (if (and  (vla-get-closed obj) (vlax-curve-isclosed obj))
    (progn
      (setq obj_arr (vlax-make-safearray vlax-vbObject '(0 . 0)))
      (vlax-safearray-put-element obj_arr 0 obj)
      (setq reg_obj (nth 0 (vlax-safearray->list (vlax-variant-value (vla-AddRegion ms obj_arr))))
            c_pt (vlax-safearray->list (vlax-variant-value (vla-get-centroid reg_obj)))
      );end_setq
      (vla-AddPoint ms (vlax-3D-point c_pt))
    );end_progn
    (alert "Passed Object is NOT Closed")
  );end_if
  (if reg_obj (vla-delete reg_obj))
  (if c_pt (setq rtn c_pt))
);end_defun

The above routine is passed the polyline object and modelspace. You can however get the modelspace object within the  routine thus eliminating the need to pass it.

 

(setq ms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))

It also inserts a point at the centroid and deletes the region object. It returns the point coordinates.

I am not one of the robots you're looking for

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks for your time and interest. I've try RH:centroid function but got the same error.

; error: AutoCAD.Application: Invalid input Automation Error. Invalid input


I have to handle those ACAD_XDICTIONARY objects.

I am thinking to do something like this:

(if (vla-get-hasextensiondictionary Object) returns :vlax-true.

(progn
        ; then make a new object using a boundary of original object and delete the original object
        ; run the Lee Mac's line to get centroid using the new object polyline created
(setq PointUEU (trans (vlax-get (setq reg (car (vlax-invoke acspc 'addregion (list obj5)))) 'Centroid) 1 0)) ; Lee Mac's

 

P.S.: Because some polyline are too far from autocad point 0,0 some centroid functions returns a wrong location to it, but Lee Mac line was working fine til I found ACAD_XDICTIONARY objects attached to a polyline entity. That's why I'ld prefer still use the Lee Mac's line.

0 Likes
Message 4 of 5

dlanorh
Advisor
Advisor
Accepted solution

Does exploding the polyline get rid of the  "ACAD_XDICTIONARY"? If so copy and explode the copied object

Try to do this if you find the polyline has xdata attached.I'm not much help as i'm far away from a copy of autocad for the weekend

 

(cond ( (/= (getvar 'peditaccept) 1) (setq pea (getvar 'peditaccept)) (setvar 'peditaccept 1)))

(setq n_obj (vla-copy obj)
          objs (vlax-safearray->list (vlax-variant-value (vla-explode n_obj)))
          sel (ssadd)
);end_setq
(foreach  a objs
  (ssadd (vlax-vla-object->ename a) sel)
)
(command "_pedit" "_M" sel "_J" 0.000 "" )
(setq n_obj (vlax-ename->vla-object (entlast)))
(if pea (setvar 'peditaccept pea))

  

I am not one of the robots you're looking for

Message 5 of 5

Anonymous
Not applicable

dlanorh with a little change I have managed to use your tip , thanks a lot.

0 Likes