LISP for Pattern Dimension

LISP for Pattern Dimension

Jason.Rugg
Collaborator Collaborator
1,077 Views
8 Replies
Message 1 of 9

LISP for Pattern Dimension

Jason.Rugg
Collaborator
Collaborator

I have an old LISP that I need to update it to format my dimension text correctly. I have not used LISP in a long time so I am lost. Using the LISP below, I need to finished dimension value to read in the following format: 

12 EQ. SP. @ 1" = <<>>

 

(defun c:@Dims (/ dist ss n eo)
 (if (and (setq dist (getdist "\nSpecify increment distance: "))
          (setq ss (ssget '((0 . "DIMENSION"))))
     )
   (progn
     (setq n (sslength ss))
     (while (> (setq n (1- n)) -1)
       (setq eo (vlax-ename->vla-object (ssname ss n)))
       (vla-put-AltUnitsScale eo dist)
       (vla-put-LinearScaleFactor eo (/ 1.0 dist))
       (vla-put-TextOverride
         eo
         (strcat "[%<\\AcExpr (1+%<\\AcObjProp Object(%<\\_ObjId "
                 (itoa (vla-get-ObjectID eo))
                 ">%).Measurement \\f \"%lu2%pr0\">%) \\f \"%lu2%pr0\">%]\\X@ %<\\AcObjProp Object(%<\\_ObjId "
                 (itoa (vla-get-ObjectID eo))
                 ">%).AltUnitsScale \\f \"%lu2%pr0\">% C/C"
         )
       )
       (vla-Update eo)
     )
   )
 )
 (command "._UpdateField" ss "")
 (princ)
)

0 Likes
1,078 Views
8 Replies
Replies (8)
Message 2 of 9

devitg
Advisor
Advisor

Please upload your sample.dwg

0 Likes
Message 3 of 9

Jason.Rugg
Collaborator
Collaborator

@devitgI don't have a sample drawing, it can be used on any dimensioned drawing. To use it, you just select two points (patterned holes) and then select the overall dimension and it does the math for you.

0 Likes
Message 4 of 9

devitg
Advisor
Advisor

How you think I can know ,how?

 

to format my dimension text correctly.

 

Please put some effort to show us how you need to be , in a sample.dwg 

0 Likes
Message 5 of 9

ronjonp
Mentor
Mentor

Maybe this?

(defun c:@dims (/ dist ss n eo)
  (if (and (setq dist (getdist "\nSpecify increment distance: "))
	   (setq ss (ssget ":L" '((0 . "DIMENSION"))))
      )
    (progn
      (setq n (sslength ss))
      (while (> (setq n (1- n)) -1)
	(setq eo (vlax-ename->vla-object (ssname ss n)))
	(vla-put-altunitsscale eo dist)
	(vla-put-linearscalefactor eo (/ 1.0 dist))
	(vla-put-textoverride
	  eo
	  (strcat
	    "%<\\AcExpr (1+%<\\AcObjProp Object(%<\\_ObjId "
	    (itoa (vla-get-objectid eo))
	    ">%).Measurement \\f \"%lu2%pr0\">%) \\f \"%lu2%pr0\">% EQ. SP.\\X@ %<\\AcObjProp Object(%<\\_ObjId "
	    (itoa (vla-get-objectid eo))
	    ">%).AltUnitsScale \\f \"%lu2%pr0\">% = <<>>"
	  )
	)
	(vla-update eo)
      )
    )
  )
  (command "._UpdateField" ss "")
  (princ)
)
Message 6 of 9

Jason.Rugg
Collaborator
Collaborator

@ronjonpThis is working pretty good, two more tweaks I need to make though. The field that gets filled in after the @ symbol, can it be formatted to have the inch " mark behind it?

 

Second, what do I need to change to get it to calculate the number of spaces for the first field? Currently it is calculating the number of objects in the pattern instead of the number of spaces between the objects in the pattern. So if I have a hole pattern with 4 holes I need it to caluculate that there are 3 equal spaces.

0 Likes
Message 7 of 9

ronjonp
Mentor
Mentor

@Jason.Rugg wrote:

@ronjonpThis is working pretty good, two more tweaks I need to make though. The field that gets filled in after the @ symbol, can it be formatted to have the inch " mark behind it?

 

Second, what do I need to change to get it to calculate the number of spaces for the first field? Currently it is calculating the number of objects in the pattern instead of the number of spaces between the objects in the pattern. So if I have a hole pattern with 4 holes I need it to caluculate that there are 3 equal spaces.


Maybe this?

Code tags seem to be busted right now that's why it's attached.

 

Changes made for reference:

image.png

0 Likes
Message 8 of 9

Jason.Rugg
Collaborator
Collaborator

@ronjonpThat worked great. I ran the code on a really big dimension and the field after @ stays in inches. So the 32'-9" increment space that I am using is filled out as 394". What keeps that in inches instead of giving me feet and inches?

0 Likes
Message 9 of 9

ronjonp
Mentor
Mentor

The units are hardcoded in the field '%lu3%pr0' <- lunits 2 luprec 0. Try this ( no lisp format ATM )

(defun c:@dims (/ dist ss n eo)
  (if (and (setq dist (getdist "\nSpecify increment distance: "))
	   (setq ss (ssget ":L" '((0 . "DIMENSION"))))
      )
    (progn
      (setq n (sslength ss))
      (while (> (setq n (1- n)) -1)
	(setq eo (vlax-ename->vla-object (ssname ss n)))
	(vla-put-altunitsscale eo dist)
	(vla-put-linearscalefactor eo (/ 1.0 dist))
	(vla-put-textoverride
	  eo
	  (strcat
	    "%<\\AcExpr (%<\\AcObjProp Object(%<\\_ObjId "
	    (itoa (vla-get-objectid eo))
	    ">%).Measurement \\f \"%lu3%pr0\">%) \\f \"%lu2%pr0\">% EQ. SP.\\X@ %<\\AcObjProp Object(%<\\_ObjId "
	    (itoa (vla-get-objectid eo))
	    ">%).AltUnitsScale \\f \"%lu3%pr0\">% = <<>>"
	  )
	)
	(vla-update eo)
      )
      (command "._UpdateField" ss "")
    )
  )
  (princ)
)

 

0 Likes