Jump to content

Selecting an entity by its variable name to substitute user selection of entity manually


RLispLearner

Recommended Posts

I am trying to automate the process of offsetting a user drawn line on both sides by 10.

I have some "offset" code I found from Lee Mac. His code first asks the user to select an entity to offset. I am trying to substitute that part with just putting in the variable name of the entity (to automate the process).

I am using entget and then the variable name to select the user drawn line but getting entity name error.

Does anyone know the proper syntax to get the entity by its name and substitute the "user select" ssget portion of the code?

 

Code below:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;create an offset of 10 on both side of a line drawn by a user                             ;;;;;
;;;                                                             ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:OLine (/ getmyline)
(command "_line" (getpoint) (getpoint "\nNext point:") ""); User draws a line between two points
(setq getmyline (cdr(assoc -1(entget (entlast))))); save the line just made to variable "getmyline"
;
;
;more code...
;more code...
;Next, use the offset code below to offset user drawn line. 
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Offset a line - By Lee Mac   (dOff.lsp)              ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (vl-load-com)

 (defun *error* ( msg )
   (and undo (vla-EndUndomark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
  )

 (if (and 
          ;(ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")));Original code. Works
          (entget (getmyline));New code - select entity by variable name. Not working...

          ;(setq of (getdist "\nSpecify Offset Distance: ")));Original code. Works
           (setq of 10);New code - Set offset distance automatically to 10
       )
   (progn
     (setq undo
       (not
         (vla-StartUndomark
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
     )
     
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
       (mapcar
         (function
           (lambda ( o )
             (vl-catch-all-apply
               (function vla-offset) (list obj o)
             )
           )
         )
         (list of (- of))
       )
     )
     (vla-delete ss)

     (setq undo (vla-EndUndoMark doc))
   )
 )
 (princ)

); End Program

Thanks in advance...

 

Link to comment
Share on other sites

1 hour ago, RLispLearner said:

I am trying to automate the process of offsetting a user drawn line on both sides by 10.

I have some "offset" code I found from Lee Mac. His code first asks the user to select an entity to offset. I am trying to substitute that part with just putting in the variable name of the entity (to automate the process).

I am using entget and then the variable name to select the user drawn line but getting entity name error.

Does anyone know the proper syntax to get the entity by its name and substitute the "user select" ssget portion of the code?

 

Code below:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;create an offset of 10 on both side of a line drawn by a user                             ;;;;;
;;;                                                             ;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:OLine (/ getmyline)
(command "_line" (getpoint) (getpoint "\nNext point:") ""); User draws a line between two points
(setq getmyline (cdr(assoc -1(entget (entlast))))); save the line just made to variable "getmyline"
;
;
;more code...
;more code...
;Next, use the offset code below to offset user drawn line. 
;
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Offset a line - By Lee Mac   (dOff.lsp)              ;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 (vl-load-com)

 (defun *error* ( msg )
   (and undo (vla-EndUndomark doc))
   (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
       (princ (strcat "\n** Error: " msg " **")))
   (princ)
  )

 (if (and 
          ;(ssget '((0 . "ARC,CIRCLE,ELLIPSE,*LINE")));Original code. Works
          (entget (getmyline));New code - select entity by variable name. Not working...

          ;(setq of (getdist "\nSpecify Offset Distance: ")));Original code. Works
           (setq of 10);New code - Set offset distance automatically to 10
       )
   (progn
     (setq undo
       (not
         (vla-StartUndomark
           (setq doc
             (vla-get-ActiveDocument
               (vlax-get-acad-object)
             )
           )
         )
       )
     )
     
     (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
       (mapcar
         (function
           (lambda ( o )
             (vl-catch-all-apply
               (function vla-offset) (list obj o)
             )
           )
         )
         (list of (- of))
       )
     )
     (vla-delete ss)

     (setq undo (vla-EndUndoMark doc))
   )
 )
 (princ)

); End Program

Thanks in advance...

 

1.

(cdr (assoc -1 (entget (entlast)))) is same with (entlast)

 

2.

The original code is written to work if the user selects with ssget in the if statement, 

so instead of putting entlast there 

You need to change it to object in obj and put it in. 

(setq ss ~ or (vlax-for obj 

or simple way

add (command "select" (entlast) "") in front of (vlax-for obj 

(vl-load-com)
(defun c:OLine (/ getmyline of undo obj ss )
  (command "_line" (getpoint) (getpoint "\nNext point:") ""); User draws a line between two points
  (setq getmyline (entlast)); save the line just made to variable "getmyline"

  ; Offset a line - By Lee Mac   (dOff.lsp)
  (defun *error* ( msg )
    (and undo (vla-EndUndomark doc))
    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
      (princ (strcat "\n** Error: " msg " **"))
    )
    (princ)
  )
  (setq of 10);New code - Set offset distance automatically to 10
  (setq undo (not (vla-StartUndomark (setq doc (vla-get-ActiveDocument (vlax-get-acad-object))))))
  (command "_.select" getmyline "")
  (vlax-for obj (setq ss (vla-get-ActiveSelectionSet doc))
    (mapcar
      (function
        (lambda ( o )
          (vl-catch-all-apply
            (function vla-offset) (list obj o)
          )
        )
      )
      (list of (- of))
    )
  )
  (vla-delete ss)
  (setq undo (vla-EndUndoMark doc))
  (princ)
); End Program

 

3.

If you want to draw multiple lines in a row, the basic command MLINE can be useful. 

You can create three or more lines by adding styles in the MLSTYLE command, 

and you can also adjust the offset between the lines by changing the Scale property within the MLINE command. 

It is also possible to add a finishing line at the end. 

If you press EXPLODE after drawing a line, it is converted into a line.

 

Edited by exceed
  • Agree 1
Link to comment
Share on other sites

This allows you to draw multiple lines before offsetting them.

-edit

Also shows a preview of the line before its created.

 

;;----------------------------------------------------------------------;;
;; Offset line(s) by 10 on both sides
(defun C:OBLine (/ ss pt1 pt2)
  (setq SS (ssadd))
  (while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nEnd point: ")))
    (entmake (list '(0 . "LINE") (cons 10 pt1) (cons 11 pt2)))
    (ssadd (entlast) ss)
  )
  (if SS
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq ent (vlax-ename->vla-object ent))
      (vla-offset ent 10)
      (vla-offset ent -10)
    )
  )
  (princ)
)

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

Thank you both guys. Each solution works great!

 

Exceed,

I didn't realize you could just use command "_.select" to grab an entity by its variable name. That's cool....

 

mhupp,

Since you used the DFX code 10 and 11 to list the end points of the user drawn line, do you know if its possible to also grab the end points of the offset lines as well?

 

Offset_end_points.thumb.PNG.69fca6497af131789e0387c91d991700.PNG

 

 

Do you think something like this would get that info and save as variables?

;Grab the endpoints of the first offset line

      (Setq offset1 (vla-offset ent 10)); save the offset "10" line to variable offset1
      (setq offset1SP1 (vlax-curve-GetStartPoint (entlast)); save startpoint of offset1
      (setq offset1EP1 (vlax-curve-GetEndPoint (entlast)); save endpoint of offset1



;Grab the endpoints of the opposite offset line

      (Setq offset2 (vla-offset ent -10)); save the offset "-10" line to variable offset2
      (setq offset2SP2 (vlax-curve-GetStartPoint (entlast)); save startpoint of offset2
      (setq offset2EP2 (vlax-curve-GetEndPoint (entlast)); save endpoint of offset2

 

 

I'm going to try to incorporate your solutions into my larger routine to see how it goes.

Thanks again guys...!

 

 

Link to comment
Share on other sites

42 minutes ago, RLispLearner said:

Thank you both guys. Each solution works great!

 

Exceed,

I didn't realize you could just use command "_.select" to grab an entity by its variable name. That's cool....

 

mhupp,

Since you used the DFX code 10 and 11 to list the end points of the user drawn line, do you know if its possible to also grab the end points of the offset lines as well?

 

Offset_end_points.thumb.PNG.69fca6497af131789e0387c91d991700.PNG

 

 

Do you think something like this would get that info and save as variables?

;Grab the endpoints of the first offset line

      (Setq offset1 (vla-offset ent 10)); save the offset "10" line to variable offset1
      (setq offset1SP1 (vlax-curve-GetStartPoint (entlast)); save startpoint of offset1
      (setq offset1EP1 (vlax-curve-GetEndPoint (entlast)); save endpoint of offset1



;Grab the endpoints of the opposite offset line

      (Setq offset2 (vla-offset ent -10)); save the offset "-10" line to variable offset2
      (setq offset2SP2 (vlax-curve-GetStartPoint (entlast)); save startpoint of offset2
      (setq offset2EP2 (vlax-curve-GetEndPoint (entlast)); save endpoint of offset2

 

 

I'm going to try to incorporate your solutions into my larger routine to see how it goes.

Thanks again guys...!

 

 

 

simple way like this

;;----------------------------------------------------------------------;;
;; Offset line(s) by 10 on both sides
(defun C:OBLine (/ ss pt1 pt2)
  (setq SS (ssadd))
  (while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nEnd point: ")))
    (entmake (list '(0 . "LINE") (cons 10 pt1) (cons 11 pt2)))
    (ssadd (entlast) ss)
  )
  (if SS
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS)))
      (setq ent (vlax-ename->vla-object ent))
      (vla-offset ent 10)
      (setq offsetline1 (vlax-ename->vla-object (entlast)))
      (vla-offset ent -10)
      (setq offsetline2 (vlax-ename->vla-object (entlast)))
      (setq offsetline1startpt (vlax-curve-GetStartPoint offsetline1))
      (setq offsetline1endpt (vlax-curve-GetEndPoint offsetline1))
      (setq offsetline2startpt (vlax-curve-GetStartPoint offsetline2))
      (setq offsetline2endpt (vlax-curve-GetEndPoint offsetline2))
      (princ "\n offset line 1 start point : ")
      (princ offsetline1startpt)
      (princ "\n offset line 1 end point : ")
      (princ offsetline1endpt)
      (princ "\n offset line 2 start point : ")
      (princ offsetline2startpt)
      (princ "\n offset line 2 end point : ")
      (princ offsetline2endpt)
    )
  )
  (princ)
)

 

 

and way without (entlast) is below

;;----------------------------------------------------------------------;;
;; Offset line(s) by 10 on both sides
(defun C:OBLine (/ ss pt1 pt2 mspace myline offsetline1 offsetline2 offsetline1startpt offsetline1endpt offsetline2startpt offsetline2endpt)
  (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  (setq ss (ssadd))
  (while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nEnd point: ")))
    (setq myline (vlax-vla-object->ename (vla-addline mspace (vlax-3d-point pt1)(vlax-3d-point pt2))))
    (ssadd myline ss)
  )
  (if SS
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq ent (vlax-ename->vla-object ent))
      (setq offsetline1 (car (vlax-safearray->list (vlax-variant-value (vla-offset ent 10)))))
      (setq offsetline2 (car (vlax-safearray->list (vlax-variant-value (vla-offset ent -10)))))
      (setq offsetline1startpt (vlax-curve-GetStartPoint offsetline1))
      (setq offsetline1endpt (vlax-curve-GetEndPoint offsetline1))
      (setq offsetline2startpt (vlax-curve-GetStartPoint offsetline2))
      (setq offsetline2endpt (vlax-curve-GetEndPoint offsetline2))
      (princ "\n offset line 1 start point : ")
      (princ offsetline1startpt)
      (princ "\n offset line 1 end point : ")
      (princ offsetline1endpt)
      (princ "\n offset line 2 start point : ")
      (princ offsetline2startpt)
      (princ "\n offset line 2 end point : ")
      (princ offsetline2endpt)
    )
  )
  (princ)
)

I like this way

 

This is using vl. However, if you create a line by changing entmake to entmakex, 

(setq myline (entmakex ~~~)) 

Since you can get the ename rather than the dxf list, you can write code without (entlast) in the same way.

https://www.cadtutor.net/forum/topic/18257-entmake-functions/

 

 

Edited by exceed
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Thanks Exceed,

I'm getting a prompt for the "start point". I have to hit enter to continue. I commented out all the Princ statements but it seems to still ask for the start point.

 

I tried changing the original code here:

 

(while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nEnd point: ")))

To 

(while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nNext point:")) "")

 

But that didn't seem to do the trick.  Would you know what I can change to fix that by chance?

 

 

Thanks again...

Link to comment
Share on other sites

8 hours ago, RLispLearner said:

Thanks Exceed,

I'm getting a prompt for the "start point". I have to hit enter to continue. I commented out all the Princ statements but it seems to still ask for the start point.

 

I tried changing the original code here:

 

(while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nEnd point: ")))

To 

(while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nNext point:")) "")

 

But that didn't seem to do the trick.  Would you know what I can change to fix that by chance?

 

 

Thanks again...

if you need continuous line

im in mobile so cannnot use <code>... 

 

(setq pt1 (getpoint "\nStart point: "))

(while  (setq pt2 (getpoint pt1 "\n next point: "))

 

...

and one more

 

(princ offsetline2endpt)

(setq pt1 pt2)

)

 

 

but you need offset line also continuously, use lwpolyline instead of line is easy

  • Like 1
Link to comment
Share on other sites

Do other way around  so exits on 1st pt if no more required. 

 

(while  (setq pt1 (getpoint "\nStart point: "))
(setq pt2 (getpoint pt1 "\n next point: "))
(command "line" pt1 pt2 "")
; offset 
) ; end while

 

If its 2 or more offsets required can do entry  like 10,-10,-15,20,-35 and so on just repeat vla-offset.

Link to comment
Share on other sites

Hi BigAl,

Needing a little more assistance if you don't mind. I added your code but still having same issue. I'm still getting a prompt "Start point" and have to manually hit enter for the offset to work. Can you run this code and let me know if you are getting the same result? I just need to offset the line once.

 

 

;;----------------------------------------------------------------------;;
;; Offset line(s) by 10 on both sides
(defun C:zzz (/ ss pt1 pt2 mspace myline offsetline1 offsetline2 offsetline1startpt offsetline1endpt offsetline2startpt offsetline2endpt)
  (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
  (setq ss (ssadd))

  ;(while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nEnd point: "))); Original
  ;(while (and (setq pt1 (getpoint "\nStart point: "))  (setq pt2 (getpoint pt1 "\nNext point:") )""); new


(while  (setq pt1 (getpoint "\nStart point: "))
(setq pt2 (getpoint pt1 "\n next point: "))
(command "line" pt1 pt2 "")
; offset 
;) ; end while


    (setq myline (vlax-vla-object->ename (vla-addline mspace (vlax-3d-point pt1)(vlax-3d-point pt2))))
    (ssadd myline ss)
  )
  (if SS
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq ent (vlax-ename->vla-object ent))
      (setq offsetline1 (car (vlax-safearray->list (vlax-variant-value (vla-offset ent 10)))))
      (setq offsetline2 (car (vlax-safearray->list (vlax-variant-value (vla-offset ent -10)))))
      (setq offsetline1startpt (vlax-curve-GetStartPoint offsetline1))
      (setq offsetline1endpt (vlax-curve-GetEndPoint offsetline1))
      (setq offsetline2startpt (vlax-curve-GetStartPoint offsetline2))
      (setq offsetline2endpt (vlax-curve-GetEndPoint offsetline2))
      ;(princ "\n offset line 1 start point : ")
      ;(princ offsetline1startpt)
      ;(princ "\n offset line 1 end point : ")
      ;(princ offsetline1endpt)
      ;(princ "\n offset line 2 start point : ")
      ;(princ offsetline2startpt)
      ;(princ "\n offset line 2 end point : ")
      ;(princ offsetline2endpt)
    )
  )
  ;(princ)
);End

 

 

 

Thanks in advance!

Link to comment
Share on other sites

There is various ways to do this this is just one way.

 

;;----------------------------------------------------------------------;;
;; Offset line(s) by 10 on both sides
(defun C:zzz (/ ss pt1 pt2 mspace myline offsetline1 offsetline2 offsetline1startpt offsetline1endpt offsetline2startpt offsetline2endpt)
  (setq mspace (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object))))
 
(while  (setq pt1 (getpoint "\nStart point: "))
        (setq pt2 (getpoint pt1 "\n next point: ")
)
      (command "line" pt1 pt2 "")

      (setq ent (vlax-ename->vla-object (entlast)))
      
      (setq offsetline1 (vla-offset ent 10))
      (setq offsetline1startpt (vlax-curve-GetStartPoint (vlax-ename->vla-object  (entlast))))
      (setq offsetline1endpt (vlax-curve-GetEndPoint (vlax-ename->vla-object (entlast))))
      
      (setq offsetline2 (vla-offset ent -10))
      (setq offsetline2startpt (vlax-curve-GetStartPoint (entlast)))
      (setq offsetline2endpt (vlax-curve-GetEndPoint (entlast)))

      (princ "\n offset line 1 start point : ")
      (princ offsetline1startpt)
      (princ "\n offset line 1 end point : ")
      (princ offsetline1endpt)
      (princ "\n offset line 2 start point : ")
      (princ offsetline2startpt)
      (princ "\n offset line 2 end point : ")
      (princ offsetline2endpt)

) ; while
  (princ)
);End

 

  • Agree 1
Link to comment
Share on other sites

21 minutes ago, RLispLearner said:

Hi BigAl,

Needing a little more assistance if you don't mind. I added your code but still having same issue. I'm still getting a prompt "Start point" and have to manually hit enter for the offset to work. Can you run this code and let me know if you are getting the same result? I just need to offset the line once.

 

Is their a reason your want to princ the endpoints? just seems like spam to me.

Link to comment
Share on other sites

8 hours ago, mhupp said:

Is their a reason your want to princ the endpoints? just seems like spam to me.

 

oh that's my spam. I forgot that I had written this haha, but it looked familiar.

 

Perhaps he wants to use this as part of another Lisp. so he wants that coordinates.

for example, make the MLINE command by autolisp

 

  • Funny 1
Link to comment
Share on other sites

This uses the line comand so one less click if your drawing multiple connected lines.

 

;;----------------------------------------------------------------------;;
;; Offset line(s) by 10 on both sides
(defun C:OBLine  (/ ss LastEnt en ent)
  (setq ss (ssadd))
  (setq LastEnt (entlast))
  (command "line" (while (= 1 (logand 1 (getvar 'CMDACTIVE))) (command pause)))
  (if (setq en (entnext LastEnt))
    (while en
      (ssadd en ss)
      (setq en (entnext en))
    )
  )
  (if (> (sslength ss) 0)
    (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))
      (setq ent (vlax-ename->vla-object ent))
      (vla-offset ent 10)
      (vla-offset ent -10)
    )
  )
  (princ)
)

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

Thanks again everyone

I think I’ve got it working now…

 

Exceed called it! This is for a larger routine and I’m needing the offset lines just for coordinates. The coordinates I need are at the ends of the offset lines (circles in yellow for illustration purposes). Everything created are just guidelines and will be deleted at the end of my final routine.

 

Here is what I have working so far. Now will see if I can implement it into my larger routine.

 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;Create rectangle. Create midpoint on shortest side. Draw midpoint line. Offset line by 10. Add circles ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun c:zzz (/ mylength mywidth pt1 pt2 pt3 pt4 pt5 pt6 offsetline1 offsetline2 offsetline1startpt offsetline1endpt offsetline2startpt offsetline2endpt)
  (vl-load-com)
  (setq oldecho (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (setq
    pt1 (getpoint "\nPick the first point")
    pt3 (getcorner "\Pick the next corner" pt1)
  )
  (vl-cmdf "_.rectang" pt1 pt3)
  (setq  pt2 (vlax-curve-getPointAtParam (entlast) 1)
         pt4 (vlax-curve-getPointAtParam (entlast) 3) 
  )
;Get length and width of rectangle
(setq mylength (distance pt1 pt2)); length
(setq mywidth (distance pt1 pt4)) ; width

;Find out which is the shorter side of the rectangle and then draw a line between the midpoints
  (if (> mywidth mylength); if mywidth is greather than mylength ( if true then...)
  (progn
    (setq pt5 (list (/ (+ (car pt1) (car pt4)) 2) (/ (+ (cadr pt1) (cadr pt4)) 2)))
    (setq pt6 (list (/ (+ (car pt2) (car pt3)) 2) (/ (+ (cadr pt2) (cadr pt3)) 2)))
    (entmake (list '(0 . "LINE")
           (cons 10 pt5)
           (cons 11 pt6)
           )
    )

;;; Create +10 Offset of Midpoint line. Draw yellow circles at each end of offset line

      (setq ent (vlax-ename->vla-object (entlast)))
      
      (setq offsetline1 (vla-offset ent 10))
      (setq offsetline1startpt (vlax-curve-GetStartPoint (vlax-ename->vla-object  (entlast))))
      (setq offsetline1endpt (vlax-curve-GetEndPoint (vlax-ename->vla-object (entlast))))
      
;Draw a circle at the end of the offset lines with diameter of 2
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline1startpt)
              (cons 40 4); size 2 diameter
         ;;color Yellow
             '(62 . 2)
        )
)
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline1endpt)
              (cons 40 4); size 2 diameter
          ;;color Yellow
             '(62 . 2)
        )
)


;;; Create -10 Offset of Midpoint line. Draw yellow circles at each end of offset line

      (setq offsetline2 (vla-offset ent -10))
      (setq offsetline2startpt (vlax-curve-GetStartPoint (entlast)))
      (setq offsetline2endpt (vlax-curve-GetEndPoint (entlast)))


;Draw a circle at the end of the offset lines with diameter of 2
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline2startpt)
              (cons 40 4); size 2 diameter
          ;;color Yellow
             '(62 . 2)
        )
)
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline2endpt)
              (cons 40 4); size 2 diameter
          ;;color Yellow
             '(62 . 2)
        )
)
  );End Progn


   ; If its not true then...

  (progn
    (setq pt5 (list (/ (+ (car pt1) (car pt2)) 2) (/ (+ (cadr pt1) (cadr pt2)) 2)))
    (setq pt6 (list (/ (+ (car pt3) (car pt4)) 2) (/ (+ (cadr pt3) (cadr pt4)) 2)))
    (entmake (list '(0 . "LINE")
           (cons 10 pt5)
           (cons 11 pt6)

           )
    )

;;; Create +10 Offset of Midpoint line. Draw yellow circles at each end of offset line


      (setq ent (vlax-ename->vla-object (entlast)))
      
      (setq offsetline1 (vla-offset ent 10))
      (setq offsetline1startpt (vlax-curve-GetStartPoint (vlax-ename->vla-object  (entlast))))
      (setq offsetline1endpt (vlax-curve-GetEndPoint (vlax-ename->vla-object (entlast))))


;Draw a circle at the end of the offset lines with diameter of 2
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline1startpt)
              (cons 40 4); size 2 diameter
          ;;color Yellow
             '(62 . 2)
        )
)
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline1endpt)
              (cons 40 4); size 2 diameter
          ;;color Yellow
             '(62 . 2)
        )
)
      
;;; Create -10 Offset of Midpoint line. Draw yellow circles at each end of offset line

      (setq offsetline2 (vla-offset ent -10))
      (setq offsetline2startpt (vlax-curve-GetStartPoint (entlast)))
      (setq offsetline2endpt (vlax-curve-GetEndPoint (entlast)))

;Draw a circle at the end of the offset lines with diameter of 2
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline2startpt)
              (cons 40 4); size 2 diameter
          ;;color Yellow
             '(62 . 2)
        )
)
(entmake
        (list '(0 . "CIRCLE")
              (cons 10  offsetline2endpt)
              (cons 40 4); size 2 diameter
          ;;color Yellow
             '(62 . 2)
        )
)

  ) ;End Progn
  ) ;_ if
  (setvar 'cmdecho oldecho)
); End Program

 

 

End result:

 

Offset_endpoints.thumb.png.1890ea83350d5b10af61e2fdd0749ad9.png

 

I appreciate everyone’s input!

  • Like 1
Link to comment
Share on other sites

So you want to draw 3 lines from 2 pick pts ?

 

What happens with this.

image.png.2439fdc185858cbd428e03b626c0332f.png

 

A more specific global style routine may be a better solution, the line intersect points can be found and the lines adjusted. It would still use offset.

 

 

If you always have a HOR VERT rectang then why not rework out the 4 pts you know offset. You can detect the line/pline at the pick point and get its angle.

 

Its nearly always better to post a diagram of what you want in 1st post.

Edited by BIGAL
  • Agree 1
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...