Jump to content

Recommended Posts

Posted

G'day Guys

 

I have a problem with getting the distance from a users. I am trying to take 3 things into concideration.

 

1. User will input 2 points in model space

2. User will input 2 points in paperspace

3. User will input the value.

 

Basicly trying to replicate "Getdist" function with it working in paper space.

 

Attached is my code.

 

(defun Sub_GetDistance (Str_Msg / Pt_Point1 Pt_Point2)
(if
	(and 
		(not (vl-catch-all-error-p (setq Pt_Point1 (vl-catch-all-apply 'getpoint (list Str_Msg)))))
		Pt_Point1
		(not (vl-catch-all-error-p (setq Pt_Point2 (vl-catch-all-apply 'getpoint (list Pt_Point1 "\nSelect second point :")))))
		Pt_Point2
	)
	(if 
		(and ;If all true measuring item in paper space through v port
			(zerop (getvar "tilemode"))
			(not (zerop (getvar "cvport")))			
		  	(setq Pt_Point1 (trans Pt_Point1 2 0)
				Pt_Point2 (trans Pt_Point2 2 0))
			(equal Pt_Point1 (osnap Pt_Point1 "_End,_Int,_Qua,_Cen,_Mid,_Node"))
			(equal Pt_Point2 (osnap Pt_Point2 "_End,_Int,_Qua,_Cen,_Mid,_Node"))
		)
	  	(distance (trans Pt_Point1 3 2)(trans Pt_Point2 3 2)) ;This only uses the latest view port created
	  	(distance Pt_Point1 Pt_Point2)
	)
)
)

Posted

I've never seen anyone post code quite like this before... Does GETDIST have a flaw that I have not observed that would prompt you to go to all of this extra effort?

 

Even if you didn't want to use GETDIST, certainly an IF statement with and AND test expression that calls GETPOINT should do the trick, no?

Posted

Yes, "GetDist" does exactly what what I require it to do, However It does not return the 'correct' length when selecting two points (osnaping to entity's) through a view port. Much the way "_.Dist" does.

Yes two 'GetPoint" 's followed with a 'GetDist" would do the trick, Which is what I have here, However I also check if the user is in paperspace and selected two points linked to an object and translate them to model points.

 

 

What do you mean "I've never seen anyone post code quite like this before" ? As is poorly written or ...?

Posted

As GETPOINT returns either nil or a valid point, perhaps I am not understanding the use of VL-CATCH-ALL-APPLY, and VL-CATCH-ALL-ERROR-P within the code you posted.

 

In my limited experience, GETPOINT is all that is needed. Please Take from this what you will, as this is meant to be helpful and not criticism of your code writing.

 

Cheers! :beer:

Posted

The reason I have included the error handling, Is if a user presses esc, I do not want the lisp program to close. In most applications I want to go back to the dialogue box.

I like to think its best that you catch every thing in a library function as you do not know what out side the function is doing.

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