TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: dubb on January 15, 2018, 03:28:49 PM

Title: How to display an end point
Post by: dubb on January 15, 2018, 03:28:49 PM
I want to know how to display an end point of a line without actually drawing a point entity. I could theoretically draw a point at the end point of a polyline and erase it. However I figure there might be a way to achieve this will grdraw or something.
Title: Re: How to display an end point
Post by: Lee Mac on January 15, 2018, 04:10:27 PM
You can display a point using grdraw/grvecs, however note that the displayed vector graphics will disappear when the screen is redrawn as the user pans or zooms, therefore, if you proceed with this route, you would need to redraw the vector graphics continuously within a grread loop.

If you did want to go with vector graphics, consider the following function:
Code: [Select]
;; grX  -  Lee Mac
;; p - [lst] WCS point at which to display 'X'
;; s - [int] size of point (in pixels)
;; c - [int] ACI colour of point
;; Returns supplied WCS point.

(defun LM:grx ( p s c / -s r q )
    (setq r (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
          q (trans p 0 3)
         -s (- s)
    )
    (grvecs
        (list c
            (list -s -s) (list s  s) (list -s (1+ -s)) (list (1- s)  s) (list (1+ -s) -s) (list s (1-  s))
            (list -s  s) (list s -s) (list -s (1-  s)) (list (1- s) -s) (list (1+ -s)  s) (list s (1+ -s))
        )
        (list
            (list r  0. 0. (car  q))
            (list 0. r  0. (cadr q))
            (list 0. 0. r  0.)
            (list 0. 0. 0. 1.)
        )
    )
    p
)

Example:
Code: [Select]
(defun c:test ( / ent )
    (if (and (setq ent (car (entsel "\nSelect polyline: ")))
             (= "LWPOLYLINE" (cdr (assoc 0 (entget ent))))
        )
        (LM:grx (trans (cdr (assoc 10 (reverse (entget ent)))) ent 0) 5 2)
    )
    (princ)
)
Title: Re: How to display an end point
Post by: dubb on January 15, 2018, 04:29:19 PM
Thanks! Very interesting and seems like I might not use vector because it might be easier for me to entmake a point, then entdel it. You always amaze me as always.
Title: Re: How to display an end point
Post by: Lee Mac on January 15, 2018, 05:53:13 PM
You're welcome, and thank you for your kind words.
Title: Re: How to display an end point
Post by: Grrr1337 on January 15, 2018, 05:59:17 PM
Theres also a Grdraw a point (http://www.theswamp.org/index.php?topic=53415.msg581221#msg581221) thread. :)
Title: Re: How to display an end point
Post by: lamarn on January 16, 2018, 01:57:22 AM
Is there also a method to display 'beginpoint', in a other format than endpoint(s) ?
Title: Re: How to display an end point
Post by: Marc'Antonio Alessi on January 16, 2018, 04:03:20 AM
I wrote this many years ago ...
Code: [Select]
; (ALE_DxfTestGrdrawX ptx ang 0 0 vwsz)
; drwcol = colore simbolo 0 > cancella freccia
; drwmod = /= 0 evidenzia la freccia
; vwsz   = (* (getvar "VIEWSIZE") 0.1)
; xtype  = 1 = X - 2 = BOX
(defun ALE_DxfTestGrdrawX (ptx drwcol drwmod vwsz xtype / pt1 pt2)
  (setq
    pt1 (list (- (car ptx) vwsz) (- (cadr ptx) vwsz))
    pt2 (list (+ (car ptx) vwsz) (+ (cadr ptx) vwsz))
  )
  (cond
    ( (= 1 xtype)
      (grdraw pt1 pt2 drwcol drwmod)
      (grdraw (list (car pt1) (cadr pt2)) (list (car pt2) (cadr pt1)) drwcol drwmod)
    )
    ( (= 2 xtype)
      (grdraw pt1 pt2 drwcol drwmod)
      (grdraw (list (car pt1) (cadr pt2)) (list (car pt2) (cadr pt1)) drwcol drwmod)
      (grdraw pt1 (list (car pt2) (cadr pt1)) drwcol drwmod)
      (grdraw (list (car pt2) (cadr pt1)) pt2 drwcol drwmod)
      (grdraw pt2 (list (car pt1) (cadr pt2)) drwcol drwmod)
      (grdraw (list (car pt1) (cadr pt2)) pt1 drwcol drwmod)
    )
  )
)
Code: [Select]
(defun c:Test (  / vwsz pt1 pt2)
  (setq vwsz (/ (getvar "VIEWSIZE") 100)   pt2 '(0 0 0))
  (while (setq pt1 (getpoint "\nPoint: "))
    (ALE_DxfTestGrdrawX pt2 0 0 vwsz 1)
    (ALE_DxfTestGrdrawX pt2 0 0 (/ vwsz 2) 2)
    (ALE_DxfTestGrdrawX pt1 2 0 vwsz 1);giallo X = inizio linea doppia
    (ALE_DxfTestGrdrawX pt2 3 0 (/ vwsz 2) 2);verde box = incrocio con pił di due entitą
    (setq pt2 pt1)
  )
  (princ)
)
Title: Re: How to display an end point
Post by: Lee Mac on January 16, 2018, 01:53:40 PM
Is there also a method to display 'beginpoint', in a other format than endpoint(s) ?

Code: [Select]
(defun c:test ( / ent enx )
    (if (and (setq ent (car (entsel "\nSelect polyline: ")))
             (= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
        )
        (progn
            (LM:grx (trans (cdr (assoc 10 enx)) ent 0) 5 3)
            (LM:grx (trans (cdr (assoc 10 (reverse enx))) ent 0) 5 1)
        )
    )
    (princ)
)
Title: Re: How to display an end point
Post by: roy_043 on January 16, 2018, 03:23:12 PM
... Elevation...
Title: Re: How to display an end point
Post by: lamarn on January 16, 2018, 04:27:56 PM
Trying to get a B and and a E to THE display for both "LINE" and "LWPOLYLINE" objects
How to get the pnt right? Snaps of code that comes into mind.

Code: [Select]

; using
  ;; Display GrText  -  Lee Mac
  ;; pnt  -  cursor point in UCS
  ;; vec  -  GrText vector list
  ;; col  -  Text Colour (ACI Colour)
  ;; xof  -  x-offset from cursor in pixels
  ;; yof  -  y-offset from cursor in pixels


    (.. (entsel "\nSelect a (poly)line: ")))
     (or
             ..
             (= "LINE" (cdr (assoc 0 (setq enx (entget ent))))))
        )
        (progn    
          ..
            (setq strB "B")
    (LM:DisplayGrText pt1 (LM:GrText strB) 1 2 2 )


Would be a cool trick
Title: Re: How to display an end point
Post by: ronjonp on January 16, 2018, 08:28:23 PM
Use:
vlax-curve-getStartPoint
vlax-curve-getEndPoint
Title: Re: How to display an end point
Post by: ScottMC on January 16, 2018, 10:05:19 PM
Hey Lee.. Just changing the [start/end] color of the selected object grips would be awesome. Have you peaked @ CATIA and do they label the 'start/end' points? Interesting software.. makes one think how good it would be if we could get more secure or/and generous and work together it would be great.
Title: Re: How to display an end point
Post by: BIGAL on January 18, 2018, 03:13:17 AM
LIke ronjonp use end & start but pick line etc near end this way can swap end values when displayed as closest as say start.
Title: Re: How to display an end point
Post by: lamarn on January 18, 2018, 04:41:50 PM
That works for the text.
Can't figure out how to get the right B/E for a straight line.
And an Arc.

Code: [Select]


(defun c:test3 (/ ent enx)
  (if
    (and (setq ent (car (entsel "\nSelect a (poly)line: ")))
(cond (
(= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
(= "LINE" (cdr (assoc 0 (setq enx (entget ent)))))
(= "ARC" (cdr (assoc 0 (setq enx (entget ent)))))
       )
)
    )
     (progn

       (LM:grx (trans (cdr (assoc 10 enx)) ent 0) 5 3)
       (LM:grx (trans (cdr (assoc 10 (reverse enx))) ent 0) 5 1)
       (setq ptB (vlax-curve-getStartPoint ent))
       (setq ptE (vlax-curve-getEndPoint ent))
       (LM:grx ptB 5 3)
       (LM:grx ptE 5 1)
       (LM:DisplayGrText ptB (LM:GrText (strcat "B")) 3 15 -15)
       (LM:DisplayGrText ptE (LM:GrText (strcat "E")) 1 15 -15)

     )
  )
  (princ)
)


Title: Re: How to display an end point
Post by: Lee Mac on January 18, 2018, 04:43:44 PM
Hint:
Code: [Select]
(LM:grx ptB 5 3)
Similar for ptE, after both have been defined.
Title: Re: How to display an end point
Post by: lamarn on January 18, 2018, 04:53:41 PM
Super ! thanks mr. Lee
updated my code in the above.
This doesn't work..(?)

(cond
..
 (= "ARC" (cdr (assoc 0 (setq enx (entget ent))))))
Title: Re: How to display an end point
Post by: Lee Mac on January 18, 2018, 04:55:04 PM
I would suggest studying the documentation for the cond function - you are using the wrong syntax.
Title: Re: How to display an end point
Post by: lamarn on January 19, 2018, 05:11:36 AM
Got it to work, except the properties don't show.
*edit: it does now*

Code: [Select]

(defun c:showSE (/ ent enx)

 (load "GrTextV1-1.lsp") ; Lee Mac

  ;; Display GrText  -  Lee Mac
  ;; pnt  -  cursor point in UCS
  ;; vec  -  GrText vector list
  ;; col  -  Text Colour (ACI Colour)
  ;; xof  -  x-offset from cursor in pixels
  ;; yof  -  y-offset from cursor in pixels
  (if (and (setq ent (car (entsel "\nSelect a (poly)line: ")))
   (or
     (= "LWPOLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
     (= "LINE" (cdr (assoc 0 (setq enx (entget ent)))))
     (= "ARC" (cdr (assoc 0 (setq enx (entget ent)))))
     (= "SPLINE" (cdr (assoc 0 (setq enx (entget ent)))))
     (= "POLYLINE" (cdr (assoc 0 (setq enx (entget ent)))))
   )
      )
    (progn

      (LM:grx (trans (cdr (assoc 10 enx)) ent 0) 5 3)
      (LM:grx (trans (cdr (assoc 10 (reverse enx))) ent 0) 5 1)
      (setq ptS (vlax-curve-getStartPoint ent))
      (setq ptE (vlax-curve-getEndPoint ent))
      (LM:grx ptS 5 3)
      (LM:grx ptE 5 1)
      (LM:DisplayGrText ptS (LM:GrText (strcat "S")) 3 10 -25)
      (LM:DisplayGrText ptE (LM:GrText (strcat "E")) 1 10 -25)
      (setq ptS nil)
      (setq ptE nil)
      (sssetfirst nil (ssadd ent (ssadd)))
    )
   
  )
 ; (princ)
)



Title: Re: How to display an end point
Post by: ronjonp on January 19, 2018, 09:22:20 AM
Instead of the command call, use this:
Code: [Select]
(sssetfirst nil (ssadd ent (ssadd)))
Title: Re: How to display an end point
Post by: lamarn on January 19, 2018, 09:27:16 AM
Thank you ronjomp!
Title: Re: How to display an end point
Post by: ronjonp on January 19, 2018, 10:37:22 AM
You're welcome :)
Title: Re: How to display an end point
Post by: dubb on January 19, 2018, 12:06:09 PM
Got it to work, except the properties don't show.
*edit: it does now*

Looks beautiful!
Title: Re: How to display an end point
Post by: roy_043 on January 19, 2018, 01:05:30 PM
@Hans:
IMO these lines can be removed:
Code: [Select]
      (LM:grx (trans (cdr (assoc 10 enx)) ent 0) 5 3)
      (LM:grx (trans (cdr (assoc 10 (reverse enx))) ent 0) 5 1)
And there are some issues regarding coordinate systems.
Title: Re: How to display an end point
Post by: lamarn on January 19, 2018, 02:03:51 PM
You're right, Roy.
It's only noice in my case.
Thanks for improvements!
Title: Re: How to display an end point
Post by: Grrr1337 on January 19, 2018, 02:08:19 PM
Hans, you could shorten the evaluations within the and function:

Code: [Select]
(and
  (setq ent (car (entsel "\nSelect a (poly)line: ")))
  (member (cdr (assoc 0 (setq enx (entget ent)))) '("LWPOLYLINE" "LINE" "ARC" "SPLINE" "POLYLINE"))
  (not (vlax-curve-isClosed ent)) ; so it will be an open curve
)
Title: Re: How to display an end point
Post by: lamarn on January 19, 2018, 02:12:25 PM
Aha. Member! A lot more professional ..;-) credits to yo all
Title: Re: How to display an end point
Post by: roy_043 on January 19, 2018, 02:23:00 PM
@Lee:
I wonder if your LM:grx function is correct. Shouldn't it be?:
Code: [Select]
;; grX  -  Lee Mac
;; p - [lst] WCS point at which to display 'X'
;; s - [int] size of point (in pixels)
;; c - [int] ACI colour of point
;; Returns supplied WCS point.

(defun LM:grx (p s c / -s r q)
  (setq r  (/ (getvar 'viewsize) (cadr (getvar 'screensize)))
        q  (trans p 0 1) ; <------- Modified
        -s (- s)
  )
  (grvecs
    (list c
    (list -s -s)
    (list s s)
    (list -s (1+ -s))
    (list (1- s) s)
    (list (1+ -s) -s)
    (list s (1- s))
    (list -s s)
    (list s -s)
    (list -s (1- s))
    (list (1- s) -s)
    (list (1+ -s) s)
    (list s (1+ -s))
    )
    (list
      (list r 0. 0. (car q))
      (list 0. r 0. (cadr q))
      (list 0. 0. r (caddr q)) ; <------- Modified
      (list 0. 0. 0. 1.)
    )
  )
  p
)

Something similar applies to the LM:displaygrtext function that Hans uses in his code.
Title: Re: How to display an end point
Post by: Lee Mac on January 19, 2018, 06:09:58 PM
@Lee:
I wonder if your LM:grx function is correct. Shouldn't it be?:

Code: [Select]
< ... >
Something similar applies to the LM:displaygrtext function that Hans uses in his code.

No, as the vector graphics should be displayed relative to the display (DCS), regardless of UCS/View.
Title: Re: How to display an end point
Post by: roy_043 on January 20, 2018, 05:09:03 AM
Thanks for your answer Lee. Hans has started a related thread on the BricsCAD forum and it seems that BC is incompatible here:
Quote from: https://forum.bricsys.com/discussion/33349/lee-mac-grtext-in-bricscad
There is a known incompatible behavior with the (grvecs) function in BricsCAD. On Acad it accepts DCS coordinates, in BricsCAD UCS.
Title: Re: How to display an end point
Post by: Lee Mac on January 20, 2018, 08:57:57 AM
Thanks for your answer Lee. Hans has started a related thread on the BricsCAD forum and it seems that BC is incompatible here:
Quote from: https://forum.bricsys.com/discussion/33349/lee-mac-grtext-in-bricscad
There is a known incompatible behavior with the (grvecs) function in BricsCAD. On Acad it accepts DCS coordinates, in BricsCAD UCS.

Thanks Roy - that clears things up.
Title: Re: How to display an end point
Post by: roy_043 on January 20, 2018, 10:01:27 AM
I have modified the ShowSE code so that it also works for BricsCAD. The code includes a modified version of Lee's LM:grx function. See my post here (https://forum.bricsys.com/discussion/comment/35268/#Comment_35268).
Title: Re: How to display an end point
Post by: Lee Mac on January 20, 2018, 11:29:50 AM
Thanks Roy - in AutoCAD (ssadd ent (ssadd)) can be (ssadd ent) - this will return a new selset containing only ent.
Title: Re: How to display an end point
Post by: roy_043 on January 21, 2018, 05:42:22 AM
Thanks Roy - in AutoCAD (ssadd ent (ssadd)) can be (ssadd ent) - this will return a new selset containing only ent.
Your suggestion also works in BricsCAD.
Title: Re: How to display an end point
Post by: lamarn on January 21, 2018, 04:27:09 PM
I like to put in the LM:GRX cross if Z is not 0.0. Very Useful for functional display and give user a hint there might be something wrong in the value (2D speaking). Checking for polyline join. Wish this turn into =>  entget / foreach for a selection.
To be nice to be able to display a complete selection this way.

If user decides to pass only 1 element then finish with statement (sssetfirst nil (ssadd ent (ssadd)))

Here is my code sofar, i'm going to dive in my archive for some good eaxples for a foreach statements ;-)

Dubb, hope you do't mind ..

Code: [Select]

(defun c:showSE (/ ent enx ptS ptE ptSz ptEz)

  ; (load "GrTextV1-1.lsp") ; Code needed : Lee Mac
  ; KGA_Geom_MatrixMake and LM:grx_BC for BricsCAD by Roy Klein Gebbinck

  ;; Display GrText  -  Lee Mac
  ;; pnt  -  cursor point in UCS
  ;; vec  -  GrText vector list
  ;; col  -  Text Colour (ACI Colour)
  ;; xof  -  x-offset from cursor in pixels
  ;; yof  -  y-offset from cursor in pixels


  (if (and
(setq ent (car (entsel "\nSelect a (poly)line: ")))
(member (cdr (assoc 0 (setq enx (entget ent))))
'("LWPOLYLINE" "LINE" "ARC" "SPLINE" "POLYLINE")
)
(not (vlax-curve-isClosed ent)) ; so it will be an open curve
      )
    (progn
      (setq ptS (vlax-curve-getStartPoint ent))
      (setq ptE (vlax-curve-getEndPoint ent))
      (setq ptSz (caddr ptS))
      (setq ptEz (caddr ptE))
      (if (= ptSz 0)
()
(if (= "BRICSCAD" (strcase (getvar 'product)))
  (progn
    (LM:grx_BC ptS 10 3)
  )
  (progn
    (LM:grx ptS 10 3)
  )
)
      )
      (if (= ptEz 0)
()
(if (= "BRICSCAD" (strcase (getvar 'product)))
  (progn
    (LM:grx_BC ptE 10 1)
  )
  (progn
    (LM:grx ptE 10 1)
  )
)
      )
      (LM:DisplayGrText ptS (LM:GrText (strcat "S")) 3 10 -25)
      (LM:DisplayGrText ptE (LM:GrText (strcat "E")) 1 10 -25)
      (setq ptS nil)
      (setq ptE nil)
      (setq ptSz nil)
      (setq ptEz nil)
      (sssetfirst nil (ssadd ent))
    )
  )
)
[\code]


Title: Re: How to display an end point
Post by: lamarn on January 23, 2018, 02:26:45 AM
For a selection of elements i made this work.

Code: [Select]

(defun c:showSE (/ ent enx ptS ptE ptSz ptEz)

  (load "GrTextV1-1.lsp") ; Lee Mac

  ;; Display GrText  -  Lee Mac
  ;; pnt  -  cursor point in UCS
  ;; vec  -  GrText vector list
  ;; col  -  Text Colour (ACI Colour)
  ;; xof  -  x-offset from cursor in pixels
  ;; yof  -  y-offset from cursor in pixel

  (setq ~CMD (getvar "CMDECHO"))
  (setvar "CMDECHO" 0)
  (setq curlay (getvar 'CLAYER))
  (setq ss1 (ssget))
  (setq count (sslength ss1)) ; to count amount of elements
  (setq number 0) ; use the number get to next
  (repeat count
    (progn
      (setq ent (ssname ss1 number)) ; selection per ent, get name of n-th element
      (setq number (1+ number)) ; add one for next volgende element na deze loop
; do ShowSE function for each entity
      (progn
(if (and
      (member (cdr (assoc 0 (setq enx (entget ent))))
      '("LWPOLYLINE" "LINE" "ARC" "SPLINE" "POLYLINE")
      )
      (not (vlax-curve-isClosed ent)) ; so it will be an open curve

    )
  (progn
    (setq ptS (vlax-curve-getStartPoint ent))
    (setq ptE (vlax-curve-getEndPoint ent))
    (setq ptSz (caddr ptS))
    (setq ptEz (caddr ptE))
    (if (= ptSz 0)
      ()
      (LM:grx ptS 10 3)
    )
    (if (= ptEz 0)
      ()
      (LM:grx ptE 10 1)
    )
    (LM:DisplayGrText ptS (LM:GrText (strcat "S")) 3 8 -8)
    (LM:DisplayGrText ptE (LM:GrText (strcat "E")) 1 8 -8)
    (setq ptS nil)
    (setq ptE nil)
    (setq ptSz nil)
    (setq ptEz nil)
  )
  ()
) ; end if
      ) ;end progn
    ) ;end progn
  ) ;end repeat   
  (setvar "CMDECHO" ~CMD)
)