Visual LISP, AutoLISP and General Customization

Reply
Valued Contributor
jcourtne
Posts: 94
Registered: ‎03-02-2010
Message 1 of 7 (622 Views)

dimensions of 3D rectangular prisms

622 Views, 6 Replies
07-16-2010 02:10 PM

I am using the attached code to find all 3D solids of a particular kind and create a report with their lengths widths and heigths.

I'm only working with rectangular prisms (boxes).

 

It works GREAT when the rectangular prism is not rotated.  When it is rotated around the z direction any, the bounding box function must stay aligned with the ucs and therefore expands to circumscribe the object.

 

I would really like this to work with a box that is rotated.

Any suggestions?

 

PS Couldn't attach the whole file so I'm going to post the subfunction here:

(defun ySolidDimensions (o_Solid / l_Boundbox r_Length r_Width r_Height l_Return)
;;; Returns the Length Width and Height of a 3DSolid
;;; Returns the Longest of either length or width first then the other
;;; Last it returns the Height (Z axis)
    ;; Check type of object given
    (if (= (yGetProp o_Solid "ObjectName") "AcDb3dSolid")
        ;; Get the bounding box dimensions
        (progn
            (vla-getboundingbox o_Solid 'minpoint 'maxpoint)
            (setq l_Boundbox (mapcar '- (vlax-safearray->list maxpoint)
                (vlax-safearray->list minpoint))
            )
        )
    )
    ;; Collect data
    (setq r_Length (car l_Boundbox))
    (setq r_Width (cadr l_Boundbox))
    (setq r_Height (caddr l_Boundbox))
    ;; Force the First number to be the longer of Length and Width
    (if (< r_Length r_Width)
            (setq l_Return (list r_Width r_Length r_Height))
            (setq l_Return (list r_Length r_Width r_Height))
    )
    l_Return
) ;_ End of function ySolidDimensions

*Expert Elite*
Kent1Cooper
Posts: 5,294
Registered: ‎09-13-2004
Message 2 of 7 (621 Views)

Re: dimensions of 3D rectangular prisms

07-16-2010 02:41 PM in reply to: jcourtne

jcourtne wrote:

I am using the attached code to find all 3D solids of a particular kind and create a report with their lengths widths and heigths.

I'm only working with rectangular prisms (boxes).

 

It works GREAT when the rectangular prism is not rotated.  When it is rotated around the z direction any, the bounding box function must stay aligned with the ucs and therefore expands to circumscribe the object.

 

I would really like this to work with a box that is rotated.

....


If you change the UCS to align with the object, its bounding box reads "correctly," though there's some conversion involved between its coordinates and World coordinates.  Something like this [partially tested]:

 

....

(command "_ucs" "_object" o_Solid)

(vla-getboundingbox o_Solid 'minpoint 'maxpoint)

(setq l_Boundbox

  (mapcar '-

    (trans (vlax-safearray->list maxpoint) 0 1)
    (trans (vlax-safearray->list minpoint) 0 1)

  )

)

(command "_ucs" "_previous")

....

 

[The UCS command may require the entity name, rather than a vla-object -- I didn't check for that.]

Kent Cooper
Valued Contributor
jcourtne
Posts: 94
Registered: ‎03-02-2010
Message 3 of 7 (600 Views)

Re: dimensions of 3D rectangular prisms

07-19-2010 11:15 AM in reply to: jcourtne

I cannot get the ucs command to work from the command line.

I can type in ucs and click on the object; but I cannot save the object and pass it to a command function in your demonstrated code. Please explain.

*Expert Elite*
Kent1Cooper
Posts: 5,294
Registered: ‎09-13-2004
Message 4 of 7 (597 Views)

Re: dimensions of 3D rectangular prisms

07-19-2010 11:32 AM in reply to: jcourtne

It wasn't intended to stand alone, but to be incorporated into your other code [that's why it has the .... ellipses before and after], where the object is presumably already saved by the parts you didn't include, and is an argument to the function, and where the dimensions will be extracted after my suggested portion, from the I_boundbox [I read that as starting with a capital I, but maybe it's a lower-case l -- change if necessary] variable.

 

If the problem is that UCS won't accept a vla-object, which presumably o_Solid is in order to get its bounding box, you may have the entity name already stored earlier in the code -- use that.  Or if the entity name isn't stored, you can get it back from the vla-object, to give to UCS, with:

 

(handent (vla-get-Handle o_Solid))

Kent Cooper
Valued Contributor
jcourtne
Posts: 94
Registered: ‎03-02-2010
Message 5 of 7 (565 Views)

Re: dimensions of 3D rectangular prisms

07-26-2010 10:49 AM in reply to: jcourtne

I still cannot get the following line to work with entities or objects

I'm using 2008. I hope that doesn't matter.

(command "_ucs" "_object" o_Solid)

 

Sorry for the delayed responce. Thanks for the help.

*Expert Elite*
Kent1Cooper
Posts: 5,294
Registered: ‎09-13-2004
Message 6 of 7 (561 Views)

Re: dimensions of 3D rectangular prisms

07-26-2010 02:20 PM in reply to: jcourtne

jcourtne wrote:

I still cannot get the following line to work with entities or objects

I'm using 2008. I hope that doesn't matter.

(command "_ucs" "_object" o_Solid)

....


I don't have 2008, but in case it's the problem I mentioned before, try:

 

(command "_.ucs" "_object" (handent (vla-get-Handle o_Solid)))

 

to give it an entity name instead of a VLA object.  If that doesn't do it [or you've tried that already], check the command-line UCS command and make sure the prompt sequence is being answered with the right things.  I know in 2004 you don't see an "OBject" option right in the base UCS prompt, so if you follow the prompts "correctly," you have to choose "New" first, and then you get the "OBject" option.  But in fact, it works to give it OB at the base prompt, even though it doesn't appear as an option there.  Maybe that flexibility has been removed in later versions, and you might need to do:

 

(command "_.ucs" "_new" "_object" (handent (vla-get-Handle o_Solid)))

 

Kent Cooper
Mentor
stevor
Posts: 839
Registered: ‎12-26-2005
Message 7 of 7 (553 Views)

Re: dimensions of 3D rectangular prisms

07-26-2010 07:49 PM in reply to: jcourtne

This works somewhat, using Kent's code:

 

{code}

 ; boundingbox
 (defun c:bbd ( / es en obn minpoint  maxpoint l_Boundbox )
  (if (and (setq es (entsel " \n Pic Sol: "))
           (setq en (car es) dl (entget en)  ty (itm_ 0 dl))
           (setq obn (vlax-ename->vla-object en)) )
   (progn
    (command "_ucs" "_object" (cadr es) )
    (vla-getboundingbox obn   'minpoint 'maxpoint)
    (setq l_Boundbox (mapcar '-
     (trans (vlax-safearray->list maxpoint) 0 1)
     (trans (vlax-safearray->list minpoint) 0 1) )
    ) (princ"\n BoundingBox Dims: ")(prin1 l_Boundbox)
   (command "_ucs" "_previous")
  ) (princ " Nyet ") )  (princ) )

{code}

S

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community