Jump to content

Program to Compute thickness automatically using AutoLISP


soham

Recommended Posts

Hello sir,

I am working on lisp in which I need your kind help.

Right now, I want to get the dimension of a component already available in 3D in AutoCAD.

For example, I have 3D drawing of component of 100x100x10 . I am stucked at this point. Please help me.

 

Thanking You,

Edited by soham
Link to comment
Share on other sites

Soham, are your 3D parts always like box 3DSOLID? You can get it's bounding box point coordinates and calculate its height... The easiest way if 3DSOLIDs are ordinary primitives not created after solid modeling operations like (union, subtract, intersect) to try this explained in this post :

http://www.cadtutor.net/forum/showthread.php?89522-Change-surface-build-settings-via-lisp&p=#6&

 

HTH

Link to comment
Share on other sites

You've made subtraction in your main 3DSOLID, so my link isn't applicable as 3DSOLID lost its primitive properties... You'll have to go another way :

 

(defun c:solhig ( / ss solobj ll ur hig )
 (vl-load-com)
 (prompt "\nPick 3D SOLID")
 (setq ss (ssget "_+.:E:S" '((0 . "3DSOLID"))))
 (while (null ss)
   (prompt "\nEmpty sel.set... Please try picking 3D SOLID again...")
   (setq ss (ssget "_+.:E:S" '((0 . "3DSOLID"))))
 )
 (setq solobj (vlax-ename->vla-object (ssname ss 0)))
 (vla-getboundingbox solobj 'll 'ur)
 (setq ll (vlax-safearray->list ll))
 (setq ur (vlax-safearray->list ur))
 (setq hig (abs (- (caddr ur) (caddr ll))))
 (prompt "\nHeight of picked 3D SOLID is : ") (princ (rtos hig 2 50))
 (princ)
)

Link to comment
Share on other sites

soham: It is not necessary to repeat a question in the same thread in back-to-back posts. Please show some patience. It also is not necessary to repeat the same question in multiple threads as it makes it difficult to follow the course of any discussion when posts are spread over two or more unrelated threads. Thank you.

Link to comment
Share on other sites

You'll just have to be patient. Those of us who choose to respond to questions here are merely volunteering our time, services and talents; we are not paid staff.

Link to comment
Share on other sites

And who will delete those posts... soham, try this code and let me know if it satisfies your needs... If that's true, please delete sufficient posts...

 

(defun c:promptdims ( / *error* incrementalpha x ss i dim value )

 (defun *error* ( msg )
   (if msg (prompt msg))
   (princ)
 )

 (defun incrementalpha ( str inc / _incrementalpha a )
  
     (defun _incrementalpha ( a b / c d e )
         (cond
             (   (cond
                     (   (< 47 (setq c (car a)) 58)
                         (setq d 48
                               e 10
                         )
                     )
                     (   (< 64 c 91)
                         (setq d 65
                               e 26
                         )
                     )
                     (   (< 96 c 123)
                         (setq d 97
                               e 26
                         )
                     )
                 )
                 (setq c (+ (- c d) b)
                       b (/ c e)
                 )
                 (cons (+ d (rem c e))
                     (if (zerop b)
                         (cdr a)
                         (if (cdr a)
                             (_incrementalpha (cdr  a) b)
                             (_incrementalpha (list d) (if (= 10 e) b (1- b)))
                         )
                     )
                 )
             )
             (   (cons c
                     (if (cdr a)
                         (_incrementalpha (cdr a) b)
                         (_incrementalpha (list 65) (1- b))
                     )
                 )
             )
         )
     )
  
     (vl-list->string
         (reverse
             (if (setq a (reverse (vl-string->list str)))
                 (_incrementalpha a inc)
                 (_incrementalpha '(65) (1- inc))
             )
         )
     )
 )

 (defun getdimmtxtvalue ( dim / e txt )
   (setq e (entlast))
   (command "_.EXPLODE" dim)
   (while (> (getvar 'cmdactive) 0) (command ""))
   (while (/= (cdr (assoc 0 (entget (setq e (entnext e))))) "MTEXT"))
   (setq txt (cdr (assoc 1 (entget e))))
   (command "_.UNDO" "")
   (setq txt (substr txt (+ 2 (vl-string-search ";" txt))))
   txt
 )

 (setq x "a")
 (prompt "\nSelect DIMENSION entities in desired order...")
 (setq ss (ssget "_:L" '((0 . "DIMENSION"))))
 (while (null ss)
   (prompt "\nEmpty sel.set... Please try selecting DIMENSION entities in desired order again...")
   (setq ss (ssget "_:L" '((0 . "DIMENSION"))))
 )
 (setq i -1)
 (repeat (sslength ss)
   (setq dim (ssname ss (setq i (1+ i))))
   (setq value (getdimmtxtvalue dim))
   (princ (strcat "\n" x "=" value))
   (setq x (incrementalpha x 1))
 )
 (*error* nil)
)

Of course, say thanks to Mr. Lee Mac for his subfunction (incrementalpha)...

M.R.

Edited by marko_ribar
Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...