+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Senior Member
    Computer Details
    flowerrobot's Computer Details
    Operating System:
    Windowns 7
    Computer:
    Lenovo W520
    Discipline
    Mechanical
    flowerrobot's Discipline Details
    Occupation
    Cad Manger
    Discipline
    Mechanical
    Using
    Mechanical 2013
    Join Date
    Sep 2007
    Location
    Sydney
    Posts
    384

    Default Getting Distance From user

    Registered forum members do not see this ad.

    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.

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

  2. #2
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,932

    Default

    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?
    "Potential has a shelf life." - Margaret Atwood

  3. #3
    Senior Member
    Computer Details
    flowerrobot's Computer Details
    Operating System:
    Windowns 7
    Computer:
    Lenovo W520
    Discipline
    Mechanical
    flowerrobot's Discipline Details
    Occupation
    Cad Manger
    Discipline
    Mechanical
    Using
    Mechanical 2013
    Join Date
    Sep 2007
    Location
    Sydney
    Posts
    384

    Default

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

  4. #4
    Forum Deity BlackBox's Avatar
    Using
    Civil 3D 2011
    Join Date
    Nov 2009
    Posts
    3,932

    Default

    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!
    "Potential has a shelf life." - Margaret Atwood

  5. #5
    Senior Member
    Computer Details
    flowerrobot's Computer Details
    Operating System:
    Windowns 7
    Computer:
    Lenovo W520
    Discipline
    Mechanical
    flowerrobot's Discipline Details
    Occupation
    Cad Manger
    Discipline
    Mechanical
    Using
    Mechanical 2013
    Join Date
    Sep 2007
    Location
    Sydney
    Posts
    384

    Default

    Registered forum members do not see this ad.

    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.

Similar Threads

  1. REQ: Place points and cumulative distance (text) on polyline, every X distance
    By enthralled in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 7th Mar 2012, 11:28 am
  2. distance in paperspace - command distance
    By flopo in forum AutoCAD General
    Replies: 9
    Last Post: 20th Jul 2011, 06:41 pm
  3. Distance
    By fostertom in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 4
    Last Post: 8th Mar 2009, 08:32 pm
  4. X distance
    By FazBear in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 1st Oct 2008, 08:46 pm

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts