PDA

View Full Version : Problem with my Utility Annotation program.


boesiii
2006-03-01, 10:12 PM
The program asks the user for the polyline, type of utility and size. Then it annotates the line with the symbol and size, it also trims out the line inside the symbol.

Problems I am having:

1. If the polyline is not inside the screen area it won't work.

2. It does not go through the entire program (sometimes), it will get hung up on a line of code at the end. Acad says there is an "error 2d/3d point nil",



(defun rtd (a)
(* (/ a pi) 180.0)
)

(defun dtr (a)
(* (/ a 180.0) pi)
)


(defun c:annotate_utility (/ utility_line utility_text utility_size scale_factor test_st utility_text_spacing
total_dist u_point u_point2 u_point3 u_point4 u_point5 u_point6 u_point7 u_point8
block_sel c_osmode c_blipmode c_cmdecho)
(setq c_osmode (getvar "osmode"))
(setq c_blipmode (getvar "blipmode"))
(setq c_cmdecho (getvar "cmdecho"))
(setq c_layer (getvar "clayer"))
(setvar "cmdecho" 0)
(setvar "blipmode" 0)
(setvar "osmode" 0)
(setq block_sel (ssadd))
(alert "This Command is based on LTSCALE")
(setq utility_line (car (entsel "\nSelect Line or Polyline to be Stationed: ")))
(ssadd utility_line block_sel)
(setq utility_text (strcase (getstring T "\nEnter Text (ex: W = Waterline): ")))
; (if (= utility_text "W")
; (progn
; (if (not (tblsearch "layer" "C-WATR"))
; (command "-layer" "m" "C-WATR" "c" "130" "" ""))
; (command "clayer" "C-WATR")))


(setq utility_size (getstring T "\nEnter Size of Utility: "))
(setq scale_factor (* (getvar "ltscale") 2))
(setq text_st (strcat "L60RS " (rtos scale_factor 2 0)))
(if (not (tblsearch "style" text_st))
(progn
(command "-style" text_st "romans" (* 0.06 scale_factor) "1"
"20" "n" "n" "n"))
(setvar "textstyle" text_st)
)


(setq utility_text_spacing (* scale_factor 0.75))
(vl-load-com)
(vlax-ename->vla-object utility_line)
(setq total_length (vlax-curve-getDistAtPoint utility_line (vlax-curve-getEndPoint utility_line)))
(setq total_dist utility_text_spacing)

(setq u_point (vlax-curve-getPointAtDist utility_line total_dist))
(setq u_point2 (vlax-curve-getPointAtDist utility_line (+ 0.001 total_dist)))
(setq u_ang (rtd (angle u_point u_point2)))
(setq u_point3 (polar u_point (+ u_ang (dtr 90)) 1))
(setq u_point4 (polar u_point (+ u_ang (dtr 270)) 1))
(command "text" "j" "mc" u_point u_ang utility_text)
(ssadd (entlast) block_sel)
(command "trim" "l" "" "f" u_point3 u_point4 "" "")
(ssadd (entlast) block_sel)
(setq size_counter 1)
(setq total_dist (+ total_dist utility_text_spacing))


(while (< total_dist (- total_length 45))
(progn
(princ (strcat "-----" (rtos total_dist 2 1) "---" (rtos total_length 2 1) "----" ))
(setq utility_line2 (entlast))
(vlax-ename->vla-object utility_line2)
(setq u_point5 (vlax-curve-getPointAtDist utility_line2 utility_text_spacing))
(setq u_point6 (vlax-curve-getPointAtDist utility_line2 (+ 0.001 utility_text_spacing)))
;;;;;-----I think this is were it hangs up--------------------
(setq u_ang2 (rtd (angle u_point5 u_point6)))
(setq u_point7 (polar u_point5 (+ u_ang2 (dtr 90)) 1))
(setq u_point8 (polar u_point5 (+ u_ang2 (dtr 270)) 1))

(if (= size_counter 2)
(progn (command "text" "j" "mc" u_point5 u_ang2 utility_size)))
(if (/= size_counter 2)
(progn (command "text" "j" "mc" u_point5 u_ang2 utility_text)))


(command "trim" "l" "" "f" u_point7 u_point8 "" "")
(setq total_dist (+ total_dist utility_text_spacing))
(setq size_counter (1+ size_counter))
(if (= size_counter 5) (setq size_counter 1))
))


;(setq block_name (getvar "date"))
;(command "._-block" block_name "0,0,0" block_sel "" )
;(command "._-insert" block_name "0,0,0" "" "" "" )

(setvar "osmode" c_osmode)
(setvar "blipmode" c_blipmode)
(setvar "cmdecho" c_cmdecho)
(princ "\n******Utiltiy Anno Worked*******")
(princ)
)

rad.77676
2006-03-02, 03:38 PM
boesiii,
I haven't had time to look at this routine, but from my own experience, I tried to write a routine that would trim utility intersections and ran into the same inconsistent behaviors.
I even went so far as to shift the view center to each intersection before trimming, but to no avail.
I ended up going with entmake to obtain the desired results, I know this doesn't help much.
Maybe someone else has some insight!
Rob

.T.
2006-03-02, 05:26 PM
Hi boesiii,

I only had a limited time to look at it, so this is more of a question than an answer:

In your code,


;snip
(setq utility_text_spacing (* scale_factor 0.75))
(vl-load-com)
(vlax-ename->vla-object utility_line)
(setq total_length (vlax-curve-getDistAtPoint utility_line (vlax-curve-getEndPoint utility_line)))
(setq total_dist utility_text_spacing)
;snip

don't you need to setq utility_line?
(setq utility_line (vlax-ename->vla-object utility_line))


Cool concept! Maybe a wish list item for custom linetypes (being able to alternate symbols)? You would still have to have several linetypes because of the variable size and type though.

boesiii
2006-03-03, 12:21 AM
Thanks guys,

I was out of the office all day, I will try your suggestions tomorrow.

boesiii
2006-03-07, 06:02 PM
I finished the main program, but still need to add error checking . Feel free to download and give it try!

rad.77676
2006-03-07, 06:31 PM
I finished the main program, but still need to add error checking . Feel free to download and give it try!

Nice!
Only problems I come up with are like you said, it hangs if the pline leaves the view and while trimming text with a fence I get an error "Cannot TRIM this object."
Seems funny since it still trims?
Rob

boesiii
2006-03-07, 07:59 PM
The error comes up because it also selects the text symbol, haven't thought of a way to fix that.

lspbox
2006-03-07, 10:21 PM
I tried your routine, have been a little while that I do not use lisp, but was thinking on a possibility, that you might already went... to be able to generate on the fly a custom linetype instead.

Here is a start


(defun C:TST (/ cLinetypeName cLinetypeShortName cLinetypeDescription ofile)
(if (and
(/= (setq cLinetypeName (strcase (getstring "nCustom linetype name: " t)))
"")
(/= (setq cLinetypeShortName (strcase (getstring "nCustom linetype short name: " t)))
"")
(/= (setq cLinetypeDescription (getstring "nCustom linetype description: " t))
""))
(progn

(vl-remove-if
'(lambda (c)
(if (= c 32)
(setq cLinetypeName (vl-string-subst "_" " " cLinetypeName))))
(vl-string->list cLinetypeName))

(if (and (not (tblsearch "LTYPE" cLinetypeName))
(setq ofile (open (findfile "acad.lin") "a")))
(progn

(write-line
(strcat "n*" cLinetypeName ","
cLinetypeDescription " ---- "
cLinetypeShortName " ---- " cLinetypeShortName
" ---- " cLinetypeShortName " ----")
ofile)

(write-line
(strcat "A,.5,-.2,[""
cLinetypeShortName
"",STANDARD,S=.1,R=0.0,X=-0.1,Y=-.05],-.2n")
ofile)

(close ofile)))

;;; (vla-load
;;; (vla-get-linetypes (vla-get-activedocument (vlax-get-acad-object)))
;;; cLinetypeName
;;; (findfile "acad.lin"))

))
(princ))


Still, requires more work... HTH