Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert dims to text LISP.. 1

Status
Not open for further replies.

basepointdesignz

Programmer
Jul 23, 2002
566
GB
Hi,

I not too hot on LISP so can anyone help me out on this one?

I want to write a small routine to allow the user to pick one or multiple dimensions and convert the dimensional values into a text version of that dim instead, like typing it in the override property areas..
Anyone know where to start with this?


Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM
XP Pro SP2
Sapphire X1950 512MB Dual-DVi Graphics Card..
 
Here's some lisp for picking one at a time. You could put it in a selection loop to more easily do multiple single picks by changing the first line to (while (setq (Diment etc....

Enjoy!

Code:
(defun c:hcd ()
  (setq DimEnt (car (entsel "\nSelect dimension to override: ")))
  (setq DimData (entget DimEnt))
  (setq DimVal (cdr (assoc 42 DimData)))
  (setq DimStyleName (cdr (assoc 3 DimData)))
  (setq DimTableData (tblsearch "DIMSTYLE" DimStyleName))
  (setq NumDec (cdr (assoc 271 DimTableData)))
  (setq DimLengthUnit (cdr (assoc 277 DimTableData)))
  (if (not DimLengthUnit) (setq DimLengthUnit (getvar "LUNITS")))
  (setq Ltext (rtos DimVal DimLengthUnit NumDec))
  (setq NewDimData (subst (cons 1 Ltext) (assoc 1 DimData) DimData))
  (entmod NewDimData)
  (princ)
)
 
That's perfect, thanks so much - works perfectly and is exactly what i asked for..

I added the while so can pick multiples but how can i sort out a window select for multiples rather than picking each in turn?

Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM
XP Pro SP2
Sapphire X1950 512MB Dual-DVi Graphics Card..
 
Yeah OK, I figured that was going to be the next request if you weren't a lisper....

Code:
(defun c:hcd ()
  (princ "\nSelect dimensions to override: ")
  (setq DimSet (ssget '((0 . "DIMENSION"))))
  (if DimSet
     (progn
        (setq NumItems (sslength DimSet))
        (setq Count 0)
        (repeat NumItems
           (setq DimEnt (ssname DimSet Count)
                 DimData (entget DimEnt)
                 DimVal (cdr (assoc 42 DimData))
                 DimStyleName (cdr (assoc 3 DimData))
                 DimTableData (tblsearch "DIMSTYLE" DimStyleName)
                 NumDec (cdr (assoc 271 DimTableData))
                 DimLengthUnit (cdr (assoc 277 DimTableData))
           )
          (if (not DimLengthUnit) (setq DimLengthUnit (getvar "LUNITS")))
          (setq Ltext (rtos DimVal DimLengthUnit NumDec))
          (setq NewDimData (subst (cons 1 Ltext) (assoc 1 DimData) DimData))
          (entmod NewDimData)
          (setq Count (1+ Count))
        );repeat
     );
  )
  (if DimSet
      (princ (strcat (itoa NumItems) " dimensions overriden with text dimension"))
      (princ "\n**No dimensions selected**")
  )
  (princ)
)
 
You are in fact a genious! That works prefectly, just what i was after. Thanks Carl..

Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM
XP Pro SP2
Sapphire X1950 512MB Dual-DVi Graphics Card..
 
You're welcome, glad to help. If I am a genious, it wasn't needed for this routine, just a little experience, and trial & error.
 
I need to learn a bit more lisp really - i know some but very limited - i'm more of a vba man myself..

Cheers,

Paul
basepointdesignzltd..
P4 3.0Ghz / 2GB RAM
XP Pro SP2
Sapphire X1950 512MB Dual-DVi Graphics Card..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top