Jump to content

Recommended Posts

Posted

Attached is a LISP file I'm writing. This is my first routine, so any comments/suggestions are welcome, just go easy... I'm working on adding error-handling, so I know that's missing for one.

 

It's a simple routine to place a block with a leader, then label with a user-entered elevation along end of the leader. I've tested the routine and it works fine but, for unknown reasons when I run it on other machines at work, I'm getting different errors.

 

At times I get an error message of "unknown command" with the text string on the command line and a number representing the direction of the line (azimuth) along the leader, but not aligned with it. Other times I get a "bad argument type" message and no text on the leader at all (as shown on the attached pdf).

 

Any ideas on what would cause either of these?

Thanks for the help.

xspot.LSP

Label1.pdf

Posted

;function to convert radians to degrees conversion function
(defun r2d (tempang)
 (* 180.0 (/ tempang pi))
)

;routine to place single existing spot elevation w/user entered elev
(defun c:xspot (/ spotloc E N Z scale loop lead1 lead2 elevstr [color="Blue"]*error*[/color])
 
[color="#0000ff"]; local error handler. DO NOT FOGET make *error* function as local variable!

 (defun *error*(msg)
   (setvar "osmode" oldosnap)
   (setvar "cmdecho" oldcmdecho)
   (setvar "dimasz" olddimasz)
   (princ "\nConsole break or Error. Exit... ")
   (princ)
   ); end of *error*
[/color]

   
 (setq oldcmdecho (getvar "cmdecho"))
 (setvar "cmdecho" 0)
 (setq olddimasz (getvar "dimasz"))
 (setvar "dimasz" 0.0)
 (setq oldosnap (getvar "osmode"))

 (while (setq spotloc (getpoint "\nPick location for spot: "))					;until "enter" get location for spot
   (progn
      (setq E (car spotloc))
      (setq N (cadr spotloc))
      (setq Z (getreal "\nEnter elevation: ")) ;get elev to use
      (setq scale (getvar "dimscale"))
      (setvar "osmode" 0)
      [color="#0000ff"](command "-insert" "spt10" (list E N Z) (* scale 0.1) "0") ; was extra ""[/color]
				;insert block at location & elev
   
      (setq lead1 (getpoint spotloc "\nPick label location: "))
      (setq lead2 (getpoint lead1 "\nPick label angle: "))
      (command "pline" spotloc lead1 lead2 "")
      (setq elevstr (rtos Z 2 1))

      (if (>=(car lead2)(car lead1))
                                                [color="#0000ff"];was empty variable tempang[/color]
         (command "text" "j" "br" lead2 (* scale 0.08) [color="#0000ff"](r2d(angle lead1 lead2)) [/color](strcat "EX" elevstr))
         (command "text" "j" "bl" lead2 (* scale 0.08) (+ 180.0[color="#0000ff"](angle lead1 lead2))[/color] (strcat "EX" elevstr))
      );end if
      (setvar "osmode" oldosnap)
   );end progn
 );end while

 (setvar "cmdecho" oldcmdecho)
 (setvar "dimasz" olddimasz)
 (princ)
)

 

And one more. Command _TEXT change syntax when fixed height texstyle is used. Use ENTMAKE function to create texts instead (command "text".

Posted

My offering:

 ;; If text height is undefined (signified by 0 in the table) 
 (if (zerop (cdr(assoc 40(tblsearch "style" (getvar "textstyle")))))
   ;; Draw the text using the current text height (textsize) 
   (command ".text" "c" "_non" txtpt "" L_Angle txt)
   ;; Otherwise use the defined text height 
   (command ".text" "c" "_non" txtpt L_Angle txt)
 ) ; endif 

 

;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
;; =    T E X T   O B J E C T  
;; =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
(setq ent
(entmakex (list (cons 0 "TEXT") ;*** 
              (cons 1 "") ;* (the string itself)
              (cons 6 "BYLAYER") ; Linetype name 
              (cons 7 "STANDARD") ;* Text style name, defaults to STANDARD, not current
              (cons 8 "0")   ; layer
              (cons 10 (list 0.0 0.0 0.0)) ;* First alignment point (in OCS) 
              (cons 11 (list 0.0 0.0 0.0)) ;* Second alignment point (in OCS) 
              (cons 39 0.0) ; Thickness (optional; default = 0)
              (cons 40 1.0) ;* Text height
              (cons 41 1.0) ; Relative X scale factor, Width Factor, defaults to 1.0
              (cons 50 0.0) ; Text rotation ange
              (cons 51 0.0) ; Oblique angle 
              (cons 62 256) ; color 
              (cons 71 0) ; Text generation flags 
              (cons 72 0) ; Horizontal text justification type 
              (cons 73 0) ; Vertical text justification type
              (cons 210 (list 0.0 0.0 1.0)))) 
)

Posted

ASMI & CAB,

 

Thanks much for your replies. I'd appreciate your input to clarify & expand on a couple of things:

 

1) ASMI, you noted I had an empty variable (tempang), which I think I had mistakenly deleted before posting. That variable is the argument to my function r2d. You accomplish basically the same thing with your changes in the next couple of lines, but wouldn't I still need the variable to feed to the r2d function? By the way, thanks for the error checking code.

 

2) Also ASMI, if I follow correctly, you indicate I should use the ENTMAKE function instead of the TEXT command to place my text labels. To help my understanding, could you explain why? You mentioned the text being fixed-height, but I have the text as a function of the dimscale [(* scale 0.08)], so to me the text isn't fixed-height.

 

3) CAB, your post seems to be the code to complete ASMI's suggestion of the ENTMAKE function. Related to #2, is the main benefit to using this function the greater "power" inherent in the function over the TEXT command?

 

4) As the next phase in this effort, once these labels are placed in a drawing, I'll need to create a lisp routine for editing them. What I'll need to accomplish with this will be to allow the user to edit the text (elevation) label & the routine will also change the Z value of the associated block. I think the main thing I'm curious about is how to relate the label with the block at the end of the leader. These elements aren't being placed all as a block. And I've thought about grouping, but I don't know if that solves the problem either? I believe the coding involved to accomplish this is a definite step beyond the first routine. Any suggestions or advice is definitely appreciated.

 

Thanks again,

TJ

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...