Lisp to dimension end point of line to perpendicular line

Lisp to dimension end point of line to perpendicular line

Jgmargarito26
Enthusiast Enthusiast
3,605 Views
12 Replies
Message 1 of 13

Lisp to dimension end point of line to perpendicular line

Jgmargarito26
Enthusiast
Enthusiast

So i do mas amount of work were i have dimension house to lot line in the surveying aspect of my work. I spent so much time to dimension from end point of house line to perpendicular to the property line. Is there any lisp out there were i can just select the house line and then the property line and throws out what ever dimension style i have?

or anything close to this. TEST DIM.JPG

0 Likes
Accepted solutions (2)
3,606 Views
12 Replies
Replies (12)
Message 2 of 13

DannyNL
Advisor
Advisor

Heading home, so real quick 'n dirty first code to test.

 

(defun c:HouseDim (/ HD_LineHouse HD_LineProperty HD_Point1 HD_BasePoint1 HD_Point2 HD_BasePoint2)
   (if
      (and
         (setq HD_LineHouse    (car (entsel "\nSelect house line   : ")))
         (setq HD_LineProperty (car (entsel "\nSelect property line: ")))
         (= (vla-get-ObjectName (setq HD_LineHouse    (vlax-ename->vla-object HD_LineHouse)))    "AcDbLine")
         (= (vla-get-ObjectName (setq HD_LineProperty (vlax-ename->vla-object HD_LineProperty))) "AcDbLine")
      )
      (progn
         (setq HD_Point1 (vlax-curve-getClosestPointTo HD_LineProperty (setq HD_BasePoint1 (vlax-safearray->list (vlax-variant-value (vla-get-StartPoint HD_LineHouse))))))
         (setq HD_Point2 (vlax-curve-getClosestPointTo HD_LineProperty (setq HD_BasePoint2 (vlax-safearray->list (vlax-variant-value (vla-get-EndPoint   HD_LineHouse))))))
         (vl-cmdf "_.DIMALIGNED" HD_BasePoint1 HD_Point1 HD_BasePoint1)
         (vl-cmdf "_.DIMALIGNED" HD_BasePoint2 HD_Point2 HD_BasePoint2)         
      )
   )
   (princ)
)
0 Likes
Message 3 of 13

Jgmargarito26
Enthusiast
Enthusiast

this is awesome, but i cant seem to move the dimension with out the dimension changing. is there anyway it can offset the measurement outwards towards the property line?

0 Likes
Message 4 of 13

scot-65
Advisor
Advisor
Another possibility would be to have utilities that can easily
set the UCS / reset UCS to World before employing the command
DIMLINEAR. Look into the UCS "Z" method.

The aligned dimension is one that I avoid as much as possible.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 5 of 13

DannyNL
Advisor
Advisor
Accepted solution

OK, updated version.

Text will be offset to property line with a distance equal to the text height of the current dimension style or override.

 

(defun c:HouseDim (/ HD_LineHouse HD_LineProperty HD_Point1 HD_BasePoint1 HD_Text1 HD_Point2 HD_BasePoint2 HD_Text2 HD_ActiveDoc HD_ActiveSpace)
   (if
      (and
         (setq HD_LineHouse    (car (entsel "\nSelect house line   : ")))
         (setq HD_LineProperty (car (entsel "\nSelect property line: ")))
         (= (vla-get-ObjectName (setq HD_LineHouse    (vlax-ename->vla-object HD_LineHouse)))    "AcDbLine")
         (= (vla-get-ObjectName (setq HD_LineProperty (vlax-ename->vla-object HD_LineProperty))) "AcDbLine")
      )
      (progn
         (vla-StartUndoMark (setq HD_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
         (setq HD_Point1 (vlax-curve-getClosestPointTo HD_LineProperty (setq HD_BasePoint1 (vlax-safearray->list (vlax-variant-value (vla-get-StartPoint HD_LineHouse))))))
         (setq HD_Point2 (vlax-curve-getClosestPointTo HD_LineProperty (setq HD_BasePoint2 (vlax-safearray->list (vlax-variant-value (vla-get-EndPoint   HD_LineHouse))))))
         (setq HD_Text1  (polar HD_Point1 (angle HD_BasePoint1 HD_Point1) (getvar "DIMTXT")))
         (setq HD_Text2  (polar HD_Point2 (angle HD_BasePoint2 HD_Point2) (getvar "DIMTXT")))
         (vla-put-TextPosition (vla-AddDimAligned (setq HD_ActiveSpace (vla-get-Block (vla-get-ActiveLayout HD_ActiveDoc))) (vlax-3d-point HD_BasePoint1) (vlax-3d-point HD_Point1) (vlax-3d-point HD_Point1)) (vlax-3d-point HD_Text1))
         (vla-put-TextPosition (vla-AddDimAligned       HD_ActiveSpace                                                      (vlax-3d-point HD_BasePoint2) (vlax-3d-point HD_Point2) (vlax-3d-point HD_Point2)) (vlax-3d-point HD_Text2))
         (vla-EndUndoMark HD_ActiveDoc)
         (mapcar 'vlax-release-object (list HD_ActiveSpace HD_ActiveDoc))
      )
   )
   (princ)
)

 

@scot-65, any particular reason why you want to avoid the aligned dimension?

0 Likes
Message 6 of 13

Jgmargarito26
Enthusiast
Enthusiast

Thank you so much this is going to be used on a daily basis with my work, i tried doing it myself but it woudnt come out how i wanted it to. What autocad are you using to create these lisp? is there anyway to offset the text like 15"? i know iam being picky at this point. 

0 Likes
Message 7 of 13

DannyNL
Advisor
Advisor

You're welcome & glad I could help Smiley Happy

 

I'm currently using AutoCAD 2014 & 2017, but these LISP codes should work I guess in AutoCAD 2000 through 2019 although I'm not able to test the older versions.

 

If you want to change the offset distance, you can change the lines of code below and  the offset distance is set by the (getvar "DIMTXT") part. 

         (setq HD_Text1  (polar HD_Point1 (angle HD_BasePoint1 HD_Point1) (getvar "DIMTXT")))
         (setq HD_Text2  (polar HD_Point2 (angle HD_BasePoint2 HD_Point2) (getvar "DIMTXT")))

 

If you want it fixed on 15", just change this into 15.

         (setq HD_Text1  (polar HD_Point1 (angle HD_BasePoint1 HD_Point1) 15))
         (setq HD_Text2  (polar HD_Point2 (angle HD_BasePoint2 HD_Point2) 15))

 

0 Likes
Message 8 of 13

scot-65
Advisor
Advisor
>>any particular reason why you want to avoid the aligned dimension?

Dimension line extensions are locked to each other
and make it difficult to grip-edit when the nodes will
no longer be parallel to the dimension line angle yet
the dimension line angle must remain as is.

(example is OP's dimension line is parallel to the [side]
property line and the dimension nodes to the house corners
are set at different distances from said property line -
the dimension line *must* be parallel to the property line)

For this, I will set the UCS axis and dimlinear.

_

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 9 of 13

DannyNL
Advisor
Advisor

OK, I see why you would want that, but to my opinion you would only benefit if you would be placing and modifying dimensions manually and not automatically.

 

Also the property boundary is not necessarily rectangular as you can see in the OP's example. So in this case the dimension is not always perpendicular to the house and only to the property boundary. And if any changes would need to be made, you would be faster by deleting the existing dimensions and running the routine again.

 

So yes, in some cases it would definitely be better to use linear dimensions like in the example you're describing. However, in this case I do not see the added value in using linear dimensions.

0 Likes
Message 10 of 13

Jgmargarito26
Enthusiast
Enthusiast

I AGREE. ALSO IS THERE ANYWAY WERE THIS LISP ROUTINE CAN ALSO DO CURVES, CAME ACROSS PROPERTIES WITH RADIUS PROPERTY LINES

0 Likes
Message 11 of 13

DannyNL
Advisor
Advisor
Accepted solution

Yes, curves for property lines should be no problem I guess, since the calculation would be the same; the shortest distance from the house to the curve.

 

However, I'm currently caught up in some other stuff for the next weeks and it is already real close to leave office into the weekend for me, so am not able to test the code you request at this moment.

 

If the code below doesn't work, hopefully somebody else will be able to modify and correct it for you.

 

(defun c:HouseDim (/ HD_LineHouse HD_LineProperty HD_Point1 HD_BasePoint1 HD_Text1 HD_Point2 HD_BasePoint2 HD_Text2 HD_ActiveDoc HD_ActiveSpace)
   (if
      (and
         (setq HD_LineHouse    (car (entsel "\nSelect house line       : ")))
         (setq HD_LineProperty (car (entsel "\nSelect property boundary: ")))
         (= (vla-get-ObjectName (setq HD_LineHouse (vlax-ename->vla-object HD_LineHouse))) "AcDbLine")         
      )
      (progn       
         (setq HD_LineProperty (vlax-ename->vla-object HD_LineProperty))
         (if           
            (not (vl-catch-all-error-p (setq HD_Point1 (vl-catch-all-apply 'vlax-curve-getClosestPointTo (list HD_LineProperty (setq HD_BasePoint1 (vlax-safearray->list (vlax-variant-value (vla-get-StartPoint HD_LineHouse)))))))))
            (progn
               (setq HD_Point2 (vlax-curve-getClosestPointTo HD_LineProperty (setq HD_BasePoint2 (vlax-safearray->list (vlax-variant-value (vla-get-EndPoint   HD_LineHouse))))))
               (setq HD_Text1  (polar HD_Point1 (angle HD_BasePoint1 HD_Point1) 15))
               (setq HD_Text2  (polar HD_Point2 (angle HD_BasePoint2 HD_Point2) 15))
               (vla-StartUndoMark (setq HD_ActiveDoc (vla-get-ActiveDocument (vlax-get-acad-object))))
               (vla-put-TextPosition (vla-AddDimAligned (setq HD_ActiveSpace (vla-get-Block (vla-get-ActiveLayout HD_ActiveDoc))) (vlax-3d-point HD_BasePoint1) (vlax-3d-point HD_Point1) (vlax-3d-point HD_Point1)) (vlax-3d-point HD_Text1))
               (vla-put-TextPosition (vla-AddDimAligned       HD_ActiveSpace                                                      (vlax-3d-point HD_BasePoint2) (vlax-3d-point HD_Point2) (vlax-3d-point HD_Point2)) (vlax-3d-point HD_Text2))
               (vla-EndUndoMark HD_ActiveDoc)
               (mapcar 'vlax-release-object (list HD_ActiveSpace HD_ActiveDoc))
            )
         )
      )
   )
   (princ)
)

 

0 Likes
Message 12 of 13

Anonymous
Not applicable

Hi, the lisp you write is great. Can you help me to modify the code to change the dimension number position like the picture below(left is your code, right is my need).Also I want to add mark to label midpoint distance between two lines.

Thanks a lot for help.

 

0 Likes
Message 13 of 13

Sea-Haven
Mentor
Mentor
The original code I think did what you want, but its not hard pick line 1 work out midpoint, pick line 2 and use getclosestpointto to get square off point then just dim align pt1 pt2 and say pt1 again.

Just think dim align snap mid, pick line, snap perp, pick other line, pick middle mid pt again all done no code.

do osmode 130 1st
0 Likes