Author Topic: 3D Solid Total Length  (Read 10888 times)

0 Members and 1 Guest are viewing this topic.

Scrutch

  • Guest
3D Solid Total Length
« on: August 10, 2007, 01:18:53 PM »
I am trying to build a routine that will return the total length of the 3D solids in a selection set.  I've tried multiple ways to do this but with the encrypted properties of the 3D solids am going in circles.  Also what would be the best way to get the selection set?  The 3d solids are on different layers...ie. lower, support, rack...etc.  Should I use a layer state save and then freeze everything else except the layer that has the 3D solids I want to get the total of?

The following code returns the largest value of the 3D solids in the Xplane, Yplane and Zplane...but I'm assuming that the length is larger than the height or width.  While 99.?? % of the time this would be true I suppose that it would be possible to get the wrong distance if the height or width were greater than the length.
The 3d solids I'm using are wbeam, channel, angle iron...etc.

I know very little about visual lisp but have a fair understanding of vanilla lisp.  Any and all help on this would be greatly appreciated.


Code: [Select]
;// Origianl code posted by naujoke ://
;// Formated & Function name catch by Adesu ://

(defun C:Solx ( / 3Ds sobj box los)
  (vl-load-com)
  (setq 3Ds (entsel "\n Select Solid :"))
  (if
    3Ds
    (progn
      (setq sobj (vlax-ename->vla-object (car 3Ds)))
      (if
 (= (vla-get-objectName sobj) "AcDb3dSolid")
 (progn
   (vla-getboundingbox sobj 'minpoint 'maxpoint)
   (setq box (mapcar '- (vlax-safearray->list maxpoint)
     (vlax-safearray->list minpoint)))
   (setq los (apply 'max box))
   (alert (strcat " Lenght of Solid = " (rtos los)))
   )    ; progn
 )      ; if
      )        ; progn
    )          ; if
  (princ)
  )            ; defun

Mark

  • Custom Title
  • Seagull
  • Posts: 28753
Re: 3D Solid Total Length
« Reply #1 on: August 10, 2007, 03:24:14 PM »
Quote
Also what would be the best way to get the selection set?

Maybe .....

Code: [Select]
(setq ss (ssget '((0 . "3DSOLID"))))
TheSwamp.org  (serving the CAD community since 2003)

Scrutch

  • Guest
Re: 3D Solid Total Length
« Reply #2 on: August 10, 2007, 04:15:26 PM »
Quote
Also what would be the best way to get the selection set?

Maybe .....

Code: [Select]
(setq ss (ssget '((0 . "3DSOLID"))))

A bit of confusion here...my question on what the best way to get the ss was in relation to the layer state.  Should I try to isolate the layer or use some kind of filter.  I've just about finished setting this up...save the layer state, set the layer I want to count current, freeze all other layers, run the routine, restore the layer state and delete the saved layer state name.  This is all with the original code, picking a single object.

My major problem is how do I count the object that I've picked and total them up.  3D solids are a bit above my coding ability.  Here's the code where I'm trying to count the solids...not sure if I've got the counter set up in the right places or not but think so.  Thanks for responding Mark.

Code: [Select]
(defun C:SolxT ( / ) ; 3dss sobj box lenth)
  (vl-load-com)
(if
(setq 3dss (ssget '((0 . "3DSOLID"))))
;//(setq 3dss(ssget))
(progn
(setq sum 0)
(setq cnt 0)
(while
(< cnt (sslength 3dss))
  (if
    3dss
    (progn
    (setq sobj (vlax-ename->vla-object (car 3dss)))
      (if
      (= (vla-get-objectName sobj) "AcDb3dSolid")
        (progn ;// progn3
        (vla-getboundingbox sobj 'minpoint 'maxpoint)
        (setq box (mapcar '- (vlax-safearray->list maxpoint)
        (vlax-safearray->list minpoint)))
        (setq lenth (apply 'max box))
        ) ;// prg
      ) ;// if
    ) ;// prg
  ) ;// if
(setq sum(+ sum lenth))
(setq cnt(+ cnt 1))
) ;// if
) ;// prg
) ;// whl
(alert (strcat " Total Length of Solid = " (rtos lenth)))
  (princ)
) ;// defun
(princ)

Scrutch

  • Guest
Re: 3D Solid Total Length
« Reply #3 on: August 10, 2007, 04:45:07 PM »
Quote
Also what would be the best way to get the selection set?

Maybe .....

Code: [Select]
(setq ss (ssget '((0 . "3DSOLID"))))

With the 3d solids for example using the above code !ss does not return the name "3DSOLID" but rather the selection set number.  When I do a properties or an entget on one of these guys everything is encrypted...like I metioned before, a bit above me.  Hopefully someone will come along and shine a light on the path.

DEVITG

  • Bull Frog
  • Posts: 479
Re: 3D Solid Total Length
« Reply #4 on: August 12, 2007, 12:27:17 PM »
SSGET return a SELECTION SET, this is not a LIST , you have to build a list of all entyname.
A question , what kind of solid are you handling.??


(defun C:SolxT ( /
3D-OBJ
3DSS
ADOC
BOX
CNT
LENTH
MAXPOINT
MINPOINT
;;SUM
)
  (vl-load-com)
 (setq   adoc
    (vla-get-activedocument
      (vlax-get-acad-object)
    )
  );_ adoc is the current DWG

(setq 3dss (ssget "X" '((0 . "3DSOLID")  ;|(cons 8  "layer1,layer2,layer3")|; ))); it will get all 3d on all layers whatsever it´s state,
;;(ssget "X") creates a selection set of all entities in the drawing including those on layers that are frozen or off.
;; you can filter to get the 3d on the selected  layers  too
     
;//(setq 3dss(ssget       )); if you want to select by user
;; see more info here , about ssget http://ronleigh.info/autolisp/afude18.htm
 



(setq sum 0)
(setq cnt 0)


(setq 3d-obj ( vla-get-activeselectionset adoc ));_ all the solids at the dwg as OBJECTS



;;;(while
;;;(< cnt )
;;;  (if
;;;    3dss
;;;    (progn
;;;    (setq sobj (vlax-ename->vla-object (car 3dss)))
;;;      (if
;;;      (= (vla-get-objectName sobj) "AcDb3dSolid")

(vlax-for 3d 3d-obj;_ same as foreach but for OBJ
  ; you do not need to check for a solid as the ssget"X" get 3dsolids only
;;;        (progn ;// progn3

  ;;(setq 3d (vla-item 3d-obj 0)); used to get the first obj , just to test de following part
        (vla-getboundingbox 3d 'minpoint 'maxpoint)

 
        (setq box (mapcar '- (vlax-safearray->list maxpoint)
        (vlax-safearray->list minpoint)))


 
        (setq lenth (apply 'max box))
;;;        )   ;// prg
;;;      )   ;// if
;;;    )   ;// prg
;;;  )   ;// if
(setq sum(+ sum lenth))
(setq cnt(+ cnt 1))
;;;)   ;// if
;;;)   ;// prg
;;;)   ;// whl
sum
  );_ vlax-for

;;(alert (strcat " Total Length of Solid = " (rtos lenth))); you have to show the sum not the Length

(alert (strcat " Total Length of Solid = " (rtos sum)))
  (princ)
   
(princ)
);// defun
;;(C:SolxT)
 
;|«Visual LISP© Format Options»
(120 2 40 0 nil "end of " 100 20 1 2 0 T nil nil T)
;*** DO NOT add text below the comment! ***|;


« Last Edit: August 12, 2007, 01:32:29 PM by DEVITG »
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

DEVITG

  • Bull Frog
  • Posts: 479
Re: 3D Solid Total Length
« Reply #5 on: August 12, 2007, 01:35:57 PM »

See your code in a other way to do it.


Code: [Select]
(defun C:SolxT ( /
3D-OBJ
3DSS
ADOC
BOX
CNT
LENTH
MAXPOINT
MINPOINT
;;SUM
)
  (vl-load-com)
 (setq adoc
(vla-get-activedocument
   (vlax-get-acad-object)
)
  );_ adoc is the current DWG

(setq 3dss (ssget "X" '((0 . "3DSOLID")  ;|(cons 8  "layer1,layer2,layer3")|; ))); it will get all 3d on all layers whatsever it´s state,
;;(ssget "X") creates a selection set of all entities in the drawing including those on layers that are frozen or off.
;; you can filter to get the 3d on the selected  layers  too
     
;//(setq 3dss(ssget       )); if you want to select by user
;; see more info here , about ssget http://ronleigh.info/autolisp/afude18.htm
 



(setq sum 0)
(setq cnt 0)


(setq 3d-obj ( vla-get-activeselectionset adoc ));_ all the solids at the dwg as OBJECTS



;;;(while
;;;(< cnt )
;;;  (if
;;;    3dss
;;;    (progn
;;;    (setq sobj (vlax-ename->vla-object (car 3dss)))
;;;      (if
;;;      (= (vla-get-objectName sobj) "AcDb3dSolid")

(vlax-for 3d 3d-obj;_ same as foreach but for OBJ
  ; you do not need to check for a solid as the ssget"X" get 3dsolids only
;;;        (progn ;// progn3

  ;;(setq 3d (vla-item 3d-obj 0)); used to get the first obj , just to test de following part
        (vla-getboundingbox 3d 'minpoint 'maxpoint)

 
        (setq box (mapcar '- (vlax-safearray->list maxpoint)
        (vlax-safearray->list minpoint)))


 
        (setq lenth (apply 'max box))
;;;        ) ;// prg
;;;      ) ;// if
;;;    ) ;// prg
;;;  ) ;// if
(setq sum(+ sum lenth))
(setq cnt(+ cnt 1))
;;;) ;// if
;;;) ;// prg
;;;) ;// whl
sum
  );_ vlax-for

;;(alert (strcat " Total Length of Solid = " (rtos lenth))); you have to show the sum not the Length

(alert (strcat " Total Length of Solid = " (rtos sum)))
  (princ)

(princ)
);// defun
;;(C:SolxT)
 
;|«Visual LISP© Format Options»
(120 2 40 0 nil "end of " 100 20 1 2 0 T nil nil T)
;*** DO NOT add text below the comment! ***|;
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Scrutch

  • Guest
Re: 3D Solid Total Length
« Reply #6 on: August 12, 2007, 08:26:48 PM »
SSGET return a SELECTION SET, this is not a LIST , you have to build a list of all entyname.
A question , what kind of solid are you handling.??

Devitg,

Whoa...thought someone was going to teach me how to fish and you've given me a whale.
The solids I'm using are WBeam, Channel Iron, Angle Iron and what not.  I've built a routine that pops up the ones I use most of the time and asks for the direction and length, then draws it for me.  I suppose I could use blocks instead but I've been doing it this way for so long that I'm very cozy with it.

I'm posting a snippet of the code here...trying to get it to just pick a layer to get the length from because the WBeam, Channel Iron and Angle Iron need to be totaled individually for the bill of material.  Can you please show me what I'm doing wrong with the layer thing?  Perhaps it's because I'm using a space in my Layer Name...?  Then perhaps I can insert a user prompt to ask for which layer to measure.  Will this (cons 8  "layer1,layer2,layer3") statement return three individual measurements...one for each layer or is it going to be a total.  At the moment I get a value of 0'-0" from one layer or several.

Have no idea how this does all this without me picking anything...it will take me quite a while to figure out the code you've posted.  GREAT JOB and Thank you ever so much.

Code: [Select]
  (vl-load-com)
 (setq adoc
(vla-get-activedocument
   (vlax-get-acad-object)
)
  );_ adoc is the current DWG

;; (setq 3dss (ssget "X" '((0 . "3DSOLID")

(cons 8  "Beam Support")

;|(cons 8  "layer1,layer2,layer3")|;
;; )))

Scrutch

  • Guest
Re: 3D Solid Total Length
« Reply #7 on: August 12, 2007, 08:49:49 PM »

See your code in a other way to do it.

Sorry, copied from the wrong place...these variations are what I've been trying to use to get a single layer...

(setq 3dss (ssget "X" '((cons 8  "Beam Lower"))))
(setq 3dss (ssget '((cons 8  "Beam Lower"))))
(setq 3dss (ssget (cons 8  "Beam Lower")))

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: 3D Solid Total Length
« Reply #8 on: August 12, 2007, 09:01:48 PM »
Try

(setq 3dss-ALL  (ssget "X" (list (cons 8 "Beam Lower"))))

(setq 3dss-SELECT (ssget (list (cons 8  "Beam Lower"))))
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

DEVITG

  • Bull Frog
  • Posts: 479
Re: 3D Solid Total Length
« Reply #9 on: August 12, 2007, 10:25:56 PM »
Hi Scrutch, can you send, or post,  a sample dwg .?
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Scrutch

  • Guest
Re: 3D Solid Total Length
« Reply #10 on: August 12, 2007, 10:47:55 PM »
Hi Scrutch, can you send, or post,  a sample dwg .?

Devitg,

This is saved as a 2000 drawing...I've got clients that have never moved forward.
I removed all the xrefs and zipped it up for you...way to big otherwised.

Thanks again for the help. :-)
Ok, now I got to figure out how to add an attachment to this guy... :?

Scrutch

  • Guest
Re: 3D Solid Total Length
« Reply #11 on: August 12, 2007, 10:52:52 PM »
Try

(setq 3dss-ALL  (ssget "X" (list (cons 8 "Beam Lower"))))

(setq 3dss-SELECT (ssget (list (cons 8  "Beam Lower"))))

Thanks Kerry...really do appreciate all the attention I'm getting here.
What a nice place this is... :-)

Scrutch

  • Guest
Re: 3D Solid Total Length
« Reply #12 on: August 12, 2007, 11:12:12 PM »
Try

(setq 3dss-ALL  (ssget "X" (list (cons 8 "Beam Lower"))))

(setq 3dss-SELECT (ssget (list (cons 8  "Beam Lower"))))

Kerry,

Strange...
(setq 3dss-ALL  (ssget "X" (list (cons 8 "Beam Lower"))))
Automatically returns total length of all solids from all layers

(setq 3dss-SELECT (ssget (list (cons 8  "Beam Lower"))))
Returns total length of all solids selected regardless of the layer they are on.
 :?

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: 3D Solid Total Length
« Reply #13 on: August 12, 2007, 11:15:01 PM »
You're welcome.
Some days you may not appreciate the attention ...

ps: I'm not all that pleasant, really .. so don't start feeling too comfortable. :|
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: 3D Solid Total Length
« Reply #14 on: August 12, 2007, 11:20:59 PM »
I just downloaded your sample drawing,

(setq 3dss-ALL  (ssget "X" (list (cons 8 "Beam Lower"))))
should return nil as there is no layer named "Beam Lower" in the drawing
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.