Jump to content

OSNAP Filter all Non-Zero Z Elevations


Brochillington

Recommended Posts

Hello Everyone,

 

A little backstory: I work in a civil land development office where feature lines are heavily used for our designs. We have some great C3D styles and labels which we use to annotate these feature lines with, however because limitations with the C3D labels they leave much to be desired drafting wise. Because of this we use mostly multileaders for the actual annotation of our design and have a set of non-plotting C3D labels to help us with the annotation. This leads to a lot of copying of numbers from the label to multileader.

 

I ended up cobbling together a lisp routine allowing the user to pick a point and have the z elevation of the point copied to the clipboard so that it can be pasted into a multileader. The lisp routine works great and gets the job done, however I find myself having to use the tab key a lot to cycle through lines until I can get the snap point on the feature line. which leads me to my question:

 

Would there be a way to filter out all non-zero z elevation snaps while calling my routine?

 

For example. I have an xref showing all my curb lines and on top of that I have another xref with all the feature line curb design elevations, if I call the command, use the nearest snap and move it to the curb line, I can watch the coordinates flicker between a Z elevation of zero and the feature line elevation depending on where I move my mouse. Would there be a way to just filter out those snapped z elevations of zero?

 

I am not the most lisp savvy person, but am willing to learn! Hoping someone can point me in the right direction here.

 

For reference, here is the lisp:

 

; Copy Z elevaiton of chose point to clipbaord 
; Command "CZ" 

(defun c:cz ()
(setq zp (rtos (caddr (getpoint "\nPick Z point: "))2 2))
(princ zp)
(_SetClipBoardText zp)
(princ)
)

(defun _SetClipBoardText ( text / htmlfile result )
   ;;  Caller's sole responsibility is to pass a
   ;;  text string. Anything else? Pie in face.
   ;;  Attribution: Reformatted version of
   ;;  post by XShrimp at theswamp.org.
   ;;  See http://tinyurl.com/2ngf4r.
(vl-load-com)
   (setq result
       (vlax-invoke
           (vlax-get
               (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow)
              'ClipBoardData
           )
          'SetData  "Text"  text)
   )
   (vlax-release-object htmlfile)
   text
)

Link to comment
Share on other sites

Maybe this will give you some ideas:

(defun c:foo (/ _dxf e el o)
 (defun _dxf (code ename) (cdr (assoc code (entget ename))))
 (cond	((null (setq e (nentsel))) (print "Bye.."))
((null (setq el (_dxf 38 (car e)))) (print "No elevation found.."))
((= 0.0 el) (print "Zero elevation.."))
(t
 (command ".mleader" (cadr e) (getpoint (cadr e)) "")
 (if (and (setq o (entlast))
	  (= "AcDbMLeader" (vla-get-objectname (setq o (vlax-ename->vla-object o))))
     )
   (vla-put-textstring o (rtos el 2 2))
 )
)
 )
 (princ)
)

Link to comment
Share on other sites

Hi Ronjop,

 

That's an interesting piece of code. I was playing around with something like that before and pieced this together a while back:

 

(defun c:melev (/ el loc z)
 (if (and (setq el (getpoint "\n Specify leader arrowhead location :"))
          (setq loc (getpoint el "\n Specify leader landing location :"))
          )  
     (command "_.mleader" "_non" (trans el 1 0) "_non" (trans loc 1 0)(rtos (caddr el) 2 2))
   (princ)
   )
 (princ)
 )

 

 

In terms of filtering non-zero Z elevation snap points I wasn't able to find much, however I did find that apparently setting the system elevation variable makes autocad favor snapping to points with a Z elevation over those that don't. In my code I simply set the elevation to 1e99 while the command is active -- seems like a bit of a hack, but it gets the job done for now.

 

I'm guessing some kind of while loop would have to be utilized to monitor what is being snapped to if I really wanted to properly do this. I saw on leemac's website there was some fancy coding for emulating osnaps and continuously displaying coordinate text next to the cursor wile a command is active. Maybe someday I'll get around to incorporating something like that, right now it all seems a bit above my head.

 

For now here is a modified version of my code from yesterday if anyone has some pointers:

 

; Copy Z elevaiton of chose point to clipbaord 
; Command "CZ" 

(defun c:cz ()
(setq syselev (getvar 'elevation))
(setq sysosnapz (getvar 'osnapz))
(defun *error* (err) ; Make sure system variables are reset on error or escape
	(setvar 'elevation syselev)  
	(setvar 'osnapz sysosnapz)
)
(setvar 'elevation 1e99)  ; Set Z elevation really high to help filter non-zero snaps
(setvar 'osnapz 0) ; Make sure z elevation snap is on
(setq zp (rtos (caddr (getpoint "\nPick Z point: "))2 2)) 
(setvar 'elevation syselev)  ; Reset Z elevation, now that we have our point 
(setvar 'osnapz sysosnapz) ; Reset OSNAPZ
(if (eq zp "1.00E+99") (setq zp ""))  ; if point is really high just return nothing
(princ zp) 
(_SetClipBoardText zp)  ; Hacky copy to clipoard command - lookup doslib if this ever breaks
(setq zp (atof zp)) ; Set zp to real for 'CAL command usage
(princ)
)

(defun _SetClipBoardText ( text / htmlfile result )
   ;;  post by XShrimp at theswamp.org.
(vl-load-com)
   (setq result
       (vlax-invoke
           (vlax-get
               (vlax-get (setq htmlfile (vlax-create-object "htmlfile")) 'ParentWindow)
              'ClipBoardData
           )
          'SetData  "Text"  text)
   )
   (vlax-release-object htmlfile)
   text
)

Link to comment
Share on other sites

Both routines have been invaluable and help serve different purposes. Creating new a multileader with the elevation works great when annotating a new design. Copying to clipboard works great when existing design has changed and the existing annotations need updating.

Link to comment
Share on other sites

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