TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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.
-
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:;; 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:
(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)
)
-
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.
-
You're welcome, and thank you for your kind words.
-
Theres also a Grdraw a point (http://www.theswamp.org/index.php?topic=53415.msg581221#msg581221) thread. :)
-
Is there also a method to display 'beginpoint', in a other format than endpoint(s) ?
-
I wrote this many years ago ...
; (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)
)
)
)
(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)
)
-
Is there also a method to display 'beginpoint', in a other format than endpoint(s) ?
(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)
)
-
... Elevation...
-
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.
; 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
-
Use:
vlax-curve-getStartPoint
vlax-curve-getEndPoint
-
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.
-
LIke ronjonp use end & start but pick line etc near end this way can swap end values when displayed as closest as say start.
-
That works for the text.
Can't figure out how to get the right B/E for a straight line.
And an Arc.
(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)
)
-
Hint:
(LM:grx ptB 5 3)
Similar for ptE, after both have been defined.
-
Super ! thanks mr. Lee
updated my code in the above.
This doesn't work..(?)
(cond
..
(= "ARC" (cdr (assoc 0 (setq enx (entget ent))))))
-
I would suggest studying the documentation for the cond function - you are using the wrong syntax.
-
Got it to work, except the properties don't show.
*edit: it does now*
(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)
)
-
Instead of the command call, use this:
(sssetfirst nil (ssadd ent (ssadd)))
-
Thank you ronjomp!
-
You're welcome :)
-
Got it to work, except the properties don't show.
*edit: it does now*
Looks beautiful!
-
@Hans:
IMO these lines can be removed:
(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.
-
You're right, Roy.
It's only noice in my case.
Thanks for improvements!
-
Hans, you could shorten the evaluations within the and function:
(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
)
-
Aha. Member! A lot more professional ..;-) credits to yo all
-
@Lee:
I wonder if your LM:grx function is correct. Shouldn't it be?:
;; 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.
-
@Lee:
I wonder if your LM:grx function is correct. Shouldn't it be?:
< ... >
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.
-
Thanks for your answer Lee. Hans has started a related thread on the BricsCAD forum and it seems that BC is incompatible here:
There is a known incompatible behavior with the (grvecs) function in BricsCAD. On Acad it accepts DCS coordinates, in BricsCAD UCS.
-
Thanks for your answer Lee. Hans has started a related thread on the BricsCAD forum and it seems that BC is incompatible here:
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.
-
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).
-
Thanks Roy - in AutoCAD (ssadd ent (ssadd)) can be (ssadd ent) - this will return a new selset containing only ent.
-
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.
-
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 ..
(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]
-
For a selection of elements i made this work.
(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)
)