Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

dimensions of 3D rectangular prisms

6 REPLIES 6
Reply
Message 1 of 7
jcourtne
1411 Views, 6 Replies

dimensions of 3D rectangular prisms

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

6 REPLIES 6
Message 2 of 7
Kent1Cooper
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, AIA
Message 3 of 7
jcourtne
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.

Message 4 of 7
Kent1Cooper
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, AIA
Message 5 of 7
jcourtne
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.

Message 6 of 7
Kent1Cooper
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, AIA
Message 7 of 7
stevor
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost