PDA

View Full Version : Tough Questions - Radius Tick Marks



johnshar123xx
2009-12-08, 03:28 PM
Tough Questions - Tick Marks


AutoCAD 2007
I have a quite a few tough questions/requests and I am currently looking for some
lisps to solve them. I have been doing some searching online to find the lisps I
need, and although I have been able to find some stuff, I still have some things
that I can't seem to find exactly what I am looking for. I would like to take
the opportunity ahead of time to thank every who views my questions and for any
help that is given.


Wondering if anyone knows if there is a way to have Autocad put tick marks at the
beginning and end of all radius arcs selected. Or if anyone has a lisp routine to do this?
I have attached a dwg example.

johnshar123xx
2010-01-06, 07:18 PM
I have been searching for a lisp that does this, and I could not find it. Then when doing a search for a different lisp I randomly found this one. It works very well, the only thing is that it does not work on polylines.

I am looking to be able to select polylines that contains straight lines and arcs and have the lisp be able to add the tick marks to the ends of each radius within the selected polylines.

Not sure if anyone knows how to edit the lisp below to enable it to do so, and would be willing to help me. If not, hopefully someone will be able to make us of it the way it is.

johnshar123xx
2010-01-15, 02:48 PM
In another forum, a member named Ollie was nice enough to write a piece of lisp to add to the "endtick.lsp" I found above, which adds polyline capabilities to the lisp. The only thing is I am not yet familiar with lisp enough to know where to insert it into the "endtick.lsp". Is there anyone who can help me combine the two. Also at the end of this it has a line of text that says "add your tick here" not sure if I need to do anything with that. The endtick.lsp I found uses endtick.dwg.




;;Not tested
;Get ent
(setq ent (vlax-ename->vla-object (car(entsel))))
;get coordinates
(setq coords (vla-get-coordinates ent))
;get vertice count
;--There is probably a ubound function to get the limit
(setq limit (/ (length(vlax-safearray->list(vlax-variant-value coords))) 2))
;set counter
(setq cntr -1)
(while(< (setq cntr (1+ cntr)) limit)
(if(/= (vla-getbulge ent limit) 0,0)
(progn
; the cntr value is the index of a bulge if the condition is met
(setq tickPoint (vla-get-coordinate coords cntr))
;add your tick here
)
)
)



Here is the "endtick.lsp" content
(In order to use it you must use the "endtick.dwg" as well because it creates the "tick" style drawn.)




;;; ENDTICK.LSP
;;;
;;; Copyright 2006 Thomas Gail Haws
;;; This program is free software under the terms of the
;;; GNU (GNU--acronym for Gnu's Not Unix--sounds like canoe)
;;; General Public License as published by the Free Software Foundation,
;;; version 2 of the License.
;;;
;;; You can redistribute this software for any fee or no fee and/or
;;; modify it in any way, but it and ANY MODIFICATIONS OR DERIVATIONS
;;; continue to be governed by the license, which protects the perpetual
;;; availability of the software for free distribution and modification.
;;;
;;; You CAN'T put this code into any proprietary package. Read the license.
;;;
;;; If you improve this software, please make a revision submittal to the
;;; copyright owner at www.hawsedc.com.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License on the World Wide Web for more details.
;;;
;;; DESCRIPTION
;;;
;;; ENDTICK inserts and aligns the ENDTICK block at the endpoint of every arc or line
;;; in a selection set. It removes duplicate ticks.
;;;
;;; ENDTICK is useful for surveying and civil engineering plans to demarcate points of
;;; curvature, tangency, et cetera.
;;;
;;; You can make your own ENDTICK block if you prefer some custom shape or size tick.
;;; The default ENDTICK block is a one unit long vertical line with its insertion point
;;; at its midpoint. ENDTICK scales the ticks to the dimension text height
;;; (dimscale * dimtext), so the default ENDTICK block will look as big as the current
;;; dimension text height.
;;;
;;; Revisions
;;; 20060914 TGH Version 1.0PR released. 3 hrs. Works only with world UCS and View

(defun c:ENDTICK () (ENDTICK))

(defun
ENDTICK
;;No global variables. All the variables should be listed here as local.
(/ CENPOINT DS DT ENDANG
ENDPOINT ENTLIST ENTNAME ENTTYPE I
MINTICKSEPARATION RADIUS SS1 STARTANG
STARTPOINT TICKLIST TS
)
;;Set initial variables
(setq
ds (getvar "dimscale")
dt (getvar "dimtxt")
ts (* ds dt)
;;If endpoints are closer together than the distance given below
;; and also aligned angularly closer than the angular difference below,
;; ENDTICK only plots the first one of them it finds.
mintickseparation
(* ts 0.01)
;;In radians. Setting to some big number like 10 (larger than 2 pi) will remove coincident ticks even with different rotations.
mintickangulardif
0.01
)
;;Get selection set from user. Limit to lines and arcs.
(setq
ss1 (ssget '((0 . "LINE,ARC")))
i -1
)
;;Get endpoints and orientations from selection set
(while (setq entname (ssname ss1 (setq i (1+ i))))
(setq
entlist
(entget entname)
enttype
(cdr (assoc 0 entlist))
)
(cond
((= enttype "LINE")
(setq
startpoint
(cdr (assoc 10 entlist))
endpoint
(cdr (assoc 11 entlist))
ticklist
(ENDTICK-addtolist
(list startpoint (angle startpoint endpoint))
ticklist
mintickseparation
mintickangulardif
)
ticklist
(ENDTICK-addtolist
(list
endpoint
(angle endpoint startpoint)
)
ticklist
mintickseparation
mintickangulardif
)
)
)

((= enttype "ARC")
(setq
cenpoint
(cdr (assoc 10 entlist))
radius
(cdr (assoc 40 entlist))
startang
(cdr (assoc 50 entlist))
endang
(cdr (assoc 51 entlist))
startpoint
(polar cenpoint startang radius)
endpoint
(polar cenpoint endang radius)
ticklist
(ENDTICK-addtolist
(list startpoint (+ startang (/ pi 2)))
ticklist
mintickseparation
mintickangulardif
)
ticklist
(ENDTICK-addtolist
(list endpoint (+ endang (/ pi 2)))
ticklist
mintickseparation
mintickangulardif
)
)
)
)
)
(setq auold (getvar "aunits"))
(setvar "aunits" 3)
(foreach
tick ticklist
(command "._insert" "endtick" (car tick) ts "" (cadr tick))
)
(setvar "aunits" auold)
)

(defun
ENDTICK-addtolist
(tick ticklist mintickseparation
mintickangulardif /
dupfound templist tickcheck
)
;;Look for duplicates in list
(setq templist ticklist)
(while (setq tickcheck (car templist))
(if (and
(< (distance (car tick) (car tickcheck)) mintickseparation)
(< (abs (- (cadr tick) (cadr tickcheck))) mintickangulardif)
)
(setq
dupfound
T
templist
nil
)
(setq templist (cdr templist))
)
)
(if (not dupfound)
(cons tick ticklist)
ticklist
)
)

irneb
2010-01-15, 08:28 PM
Maybe this could work, I've added comments to show what I've added / changed:
;;; ENDTICK.LSP
;;;
;;; Copyright 2006 Thomas Gail Haws
;;; This program is free software under the terms of the
;;; GNU (GNU--acronym for Gnu's Not Unix--sounds like canoe)
;;; General Public License as published by the Free Software Foundation,
;;; version 2 of the License.
;;;
;;; You can redistribute this software for any fee or no fee and/or
;;; modify it in any way, but it and ANY MODIFICATIONS OR DERIVATIONS
;;; continue to be governed by the license, which protects the perpetual
;;; availability of the software for free distribution and modification.
;;;
;;; You CAN'T put this code into any proprietary package. Read the license.
;;;
;;; If you improve this software, please make a revision submittal to the
;;; copyright owner at www.hawsedc.com.
;;;
;;; This program is distributed in the hope that it will be useful,
;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;; GNU General Public License on the World Wide Web for more details.
;;;
;;; DESCRIPTION
;;;
;;; ENDTICK inserts and aligns the ENDTICK block at the endpoint of every arc or line
;;; in a selection set. It removes duplicate ticks.
;;;
;;; ENDTICK is useful for surveying and civil engineering plans to demarcate points of
;;; curvature, tangency, et cetera.
;;;
;;; You can make your own ENDTICK block if you prefer some custom shape or size tick.
;;; The default ENDTICK block is a one unit long vertical line with its insertion point
;;; at its midpoint. ENDTICK scales the ticks to the dimension text height
;;; (dimscale * dimtext), so the default ENDTICK block will look as big as the current
;;; dimension text height.
;;;
;;; Revisions
;;; 20060914 TGH Version 1.0PR released. 3 hrs. Works only with world UCS and View

;;; Modified by Irné Barnard on 2010-01-15 to allow for polylines as well, noted with comments starting with IB:

(vl-load-com) ;IB: Ensure VLisp extensions are loaded

(defun c:ENDTICK () (ENDTICK))

(defun ENDTICK ;;No global variables. All the variables should be listed here as local.
(/ CENPOINT DS DT ENDANG ENDPOINT ENTLIST ENTNAME
ENTTYPE I MINTICKSEPARATION RADIUS SS1 STARTANG STARTPOINT
TICKLIST TS ENTOBJ ;IB: Added ENTOBJ for ActiveX object reference
)
;;Set initial variables
(setq ds (getvar "dimscale")
dt (getvar "dimtxt")
ts (* ds dt)
;;If endpoints are closer together than the distance given below
;; and also aligned angularly closer than the angular difference below,
;; ENDTICK only plots the first one of them it finds.
mintickseparation (* ts 0.01)
;;In radians. Setting to some big number like 10 (larger than 2 pi) will remove coincident ticks even with different rotations.
mintickangulardif 0.01
) ;_ end of setq
;;Get selection set from user. Limit to lines and arcs.
(setq ss1 (ssget '((0 . "LINE,ARC,LWPOLYLINE,POLYLINE"))) ;IB: Added LWPOLYLINE and POLYLINE
i -1
) ;_ end of setq
;;Get endpoints and orientations from selection set
(while (setq entname (ssname ss1 (setq i (1+ i))))
(setq
entlist (entget entname)
enttype (cdr (assoc 0 entlist))
) ;_ end of setq
(cond
((= enttype "LINE")
(setq
startpoint (cdr (assoc 10 entlist))
endpoint (cdr (assoc 11 entlist))
ticklist (ENDTICK-addtolist
(list startpoint (angle startpoint endpoint))
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist
ticklist (ENDTICK-addtolist
(list
endpoint
(angle endpoint startpoint)
) ;_ end of list
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist
) ;_ end of setq
)

((= enttype "ARC")
(setq
cenpoint (cdr (assoc 10 entlist))
radius (cdr (assoc 40 entlist))
startang (cdr (assoc 50 entlist))
endang (cdr (assoc 51 entlist))
startpoint (polar cenpoint startang radius)
endpoint (polar cenpoint endang radius)
ticklist (ENDTICK-addtolist
(list startpoint (+ startang (/ pi 2)))
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist
ticklist (ENDTICK-addtolist
(list endpoint (+ endang (/ pi 2)))
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist
) ;_ end of setq
)

;; IB: Section added to do Polyline's
((wcmatch enttype "LWPOLYLINE,POLYLINE")
(setq
ENTOBJ (vlax-ename->vla-object entname) ;Get the ActiveX object reference from the ename
startpoint (vlax-curve-getStartPoint ENTOBJ) ;Get the start point
endpoint (vlax-curve-getEndPoint ENTOBJ) ;Get the end point
startang (vlax-curve-getStartParam ENTOBJ) ;Get the start angle
endang (vlax-curve-getEndParam ENTOBJ) ;Get the end angle
ticklist (ENDTICK-addtolist
(list startpoint (angle startpoint endpoint))
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist
ticklist (ENDTICK-addtolist
(list
endpoint
(angle endpoint startpoint)
) ;_ end of list
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist
) ;_ end of setq
) ;IB: End of section added
) ;_ end of cond
) ;_ end of while
(setq auold (getvar "aunits"))
(setvar "aunits" 3)
(foreach tick ticklist
(command "._insert" "endtick" (car tick) ts (Rad2Deg (cadr tick))) ;IB: Added Rad2Deg to convert from Radians to Degrees
) ;_ end of foreach
(setvar "aunits" auold)
) ;_ end of defun

;; IB: Added function to convert Radians to Degrees
(defun Rad2Deg (Rad /) (* 180.0 (/ Rad pi)))

(defun ENDTICK-addtolist (tick ticklist mintickseparation mintickangulardif / dupfound templist tickcheck)
;;Look for duplicates in list
(setq templist ticklist)
(while (setq tickcheck (car templist))
(if (and
(< (distance (car tick) (car tickcheck)) mintickseparation)
(< (abs (- (cadr tick) (cadr tickcheck))) mintickangulardif)
) ;_ end of and
(setq
dupfound
T
templist
nil
) ;_ end of setq
(setq templist (cdr templist))
) ;_ end of if
) ;_ end of while
(if (not dupfound)
(cons tick ticklist)
ticklist
) ;_ end of if
) ;_ end of defun

johnshar123xx
2010-01-18, 04:26 PM
Thank you irneb for your response and for you lisp, it is greatly appreciated.
At first I just loaded the lisp quickly to give it a try and I was unable to get the lisp to work.
Then I opened it up to read your comments (which was very helpful to see and learn a little of what needed to be edited) and I read about the need to load the "VL-LOAD-COM, which I am unaware of how to load this.
I have been doing a little research on how to load this command, and I will post a response once I have learned how to do so, and when I have tested out the lisp you supplied.

I thank you again for you help and as mentioned I will keep you updated.

irneb
2010-01-19, 04:53 AM
The (vl-load-com) call I've added should be all that's necessary to load the VL Extensions. I've added 5 functions which are part of these VL Extensions:

vlax-ename->vla-object
vlax-curve-getStartPoint
vlax-curve-getStartParam
vlax-curve-getEndPoint
vlax-curve-getEndParamIf your AC 2007 can't use these there's something wrong with it's installation. These were definitely available prior to 2007, and forms part of the normal Vanilla AutoCAD installation.

johnshar123xx
2010-01-20, 04:52 PM
Again I thank you irneb for your help, unfortunately I am still having some trouble.
I created a completely new drawing and in it I drew a polyline composed of a two straight lines connected by a radius. I tried loading the lisp in this new drawing, and I now don't get the vl load error, but the lisp just puts one large tick mark at the beginning of the polyline and it asks the rotation for it. I can't seem to get the lisp to react like the "endtick.lisp" I supplied, where it automatically puts the ticks at the ends of the each radius, and the ticks are automatically cross the perpendicular to the polyline.

If you are unable to get it to work, that is fine, I really appreciate your help in trying to come up with a solution for me.

irneb
2010-01-21, 07:23 AM
It depends on the version of ACad. I'm using Vanilla 2008 at the moment, I know there was some changes prior and after 2008, so that may be why yours is not working correctly. Check the (command "._insert" "endtick" line, and compare it to the prompts you'd give after an -INSERT command (note hyphen prefix to not use the dialog). That's probably where the difference comes in.

johnshar123xx
2010-01-21, 05:03 PM
Hey irneb, thanks again for getting back to me, I had someone I work with try it in AutoCAD 2008 and he got the same effect as I did, where it tries putting just one giant tickmark at the end of the polyline (asking for a rotation angle) instead of a small tickmark block at the ends of every radius automatically.

I would mainly use this lisp in civil plans where units are set to decimal and the ltscale is usually set to around 40.00 (for a 40 scale drawing)

Below is what the lisp reads when entered in the command line



Command: endtick
Select objects: 1 found
Select objects:
._insert Enter block name or [?] <endtick>: endtick
Units: Feet Conversion: 1.0000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>:
7.200000000000000 Enter Y scale factor <use X scale factor>: 315.0000000000000
Specify rotation angle <0r>: ._insert
Requires valid numeric angle or second point.
; error: Function cancelled
Specify rotation angle <0r>:



I also found this lisp below that maybe can help as well, or maybe someone else can use it as is. It is pretty cool, meant for pipes. The reason why I figured it may be helpful is that it places lines at the ends of radii, but unfortunately the tickmarks lines are not blocks.

Again thank you

irneb
2010-01-22, 05:22 AM
Oh sorry, I think I see where the problem is: If the block was defined with uniform scaling it doesn't ask for Y. And I used a uniform block to test the code. For a non-uniform scaled block the command call should look like this:

(command "._insert" "endtick" (car tick) ts "" (Rad2Deg (cadr tick)))Notice the empty string which means an Enter key when asked for the Y scale factor. You could have sent the ts again, but it does the same thing.

irneb
2010-01-22, 07:00 AM
Sorry another thing I've done wrong: getStartParam & getEndParam doesn't give the angle of the line / polyline at that point. These 2 lines of code should rather look like this:
startang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv ENTOBJ (vlax-curve-getStartPoint ENTOBJ))) ;Get the start angle
endang (angle '(0.0 0.0 0.0) (vlax-curve-getFirstDeriv ENTOBJ (vlax-curve-getEndPoint ENTOBJ))) ;Get the end angle
Edit: And then I should use these to create the tick :Oops:
ticklist (ENDTICK-addtolist
(list startpoint (+ startang (/ pi 2)))
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist
ticklist (ENDTICK-addtolist
(list endpoint (+ endang (/ pi 2)))
ticklist
mintickseparation
mintickangulardif
) ;_ end of ENDTICK-addtolist

irneb
2010-01-22, 07:39 AM
OK this now seems to work in both cases (uniform & non-uniformly scaled).

johnshar123xx
2010-01-27, 03:51 PM
Hey irneb thank you so much for continuing to help me.
Still no luck at getting the lisp to work for me, I get one of two scenarios..

1. it kicks back this response
Please note, block [endtick] is not available in this drawing. Change the name
used in the LSP file or insert the block to this drawing.0

2. it places a large tick mark at one end of the polyline going the same direction as the line where it looks like it is extending the line.

I would like the lisp to use the endtick.dwg block file that comes, if it can be done, because this way I could modify the block drawing, and it will change all of them at the same time.

Like I said, if this can't be done, that is alright, I really appreciate your continued help.

irneb
2010-01-28, 05:19 AM
The first error is because the ENDTICK block is not part of the current DWG. You could change the lisp in to insert it from a file if it's not in the DWG yet. Otherwise it will fail somewhere else.

As for the "large" - it's scaled according to the DIMSCALE x DIMTXT, which means it gets scaled to suit the current dimension text height. If the endtick's overall size is one unit it will be the same length as the dim text's height.

As for the angle, you could always add 90 degrees to the insert rotation. Either add it thus:
(command "._insert" ...... (+ 90.0 (Rad2Deg (cadr tick))))Or prior to converting to degrees add half a PI:
(command "._insert" ...... (Rad2Deg (+ (/ pi 2) (cadr tick))))

johnshar123xx
2010-02-08, 03:58 PM
Again Irneb, I thank you for your help and your continuing patience.

I apologize, I am still not quite at a level to edit and or know where to enter pieces of code within a lisp.

If you have some time would you be able to show me how to add to the lisp, how to add the "endtick.dwg" block to the drawing automatically when the lisp is activated? and also show me where to enter the tick rotation codes to the current lisp you have worked on for me?

I have been trying to mess around with the lisp, but I still cannot seem to get it to react like the original lisp I supplied. It always seem to put the tick at the end of the polyline selected, and not at the ends of all the radii within the polyline.

Thanks again for your help

irneb
2010-02-09, 06:25 PM
No prob, I'll try and help - but I can't do this quickly for you, I have a quite pressing project at the moment :mrgreen:
If you have some time would you be able to show me how to add to the lisp, how to add the "endtick.dwg" block to the drawing automatically when the lisp is activated?I don't think it's really necessary. Just WBLOCK the endtick out to one of your support folders. The INSERT command will then notice that the block isn't in the current drawing and search these folders for a DWG file with that name, if found it will import.
It always seem to put the tick at the end of the polyline selected, and not at the ends of all the radii within the polyline.Woha! That's not how I understood it before. Sorry, will have to look into this again!

johnshar123xx
2010-02-11, 10:12 PM
Not a problem at all, I thank you again for your continuing help.

Just to summarize again what I am looking for help with....

The original lisp I supplied called endtick.lsp works great, it puts tick marks at each end of every arc selected. The code is not setup for the lisp to detect arcs inside of a joined polylines. I was hoping someone would be able to update the lisp for it to work with arcs in a polyline so I could just select a polyline with multiple arcs joined and it will add that endtick.dwg perpendicular at the vertice ends of each arc. This way I would not have to explode the polyline to run the lisp and then rejoin the polyline after. Also, the "endtick.dwg" I supplied came with the lisp, you have to place this in the "support" folder, Which I have done. The lisp code is written to call upon that endtick.dwg.

Not sure if this helps, a user by the name of ollie on another forum supplied the code below to help, but I couldn't really understand how to apply it, this user hasn't responded back in a while. Maybe this could help you?



;;Not tested
;Get ent
(setq ent (vlax-ename->vla-object (car(entsel))))
;get coordinates
(setq coords (vla-get-coordinates ent))
;get vertice count
;--There is probably a ubound function to get the limit
(setq limit (/ (length(vlax-safearray->list(vlax-variant-value coords))) 2))
;set counter
(setq cntr -1)
(while(< (setq cntr (1+ cntr)) limit)
(if(/= (vla-getbulge ent limit) 0,0)
(progn
; the cntr value is the index of a bulge if the condition is met
(setq tickPoint (vla-get-coordinate coords cntr))
;add your tick here
)
)
)