Results 1 to 9 of 9

Thread: Lisp to draw right angle lines?

  1. #1
    Member
    Join Date
    2005-10
    Posts
    2
    Login to Give a bone
    0

    Default Lisp to draw right angle lines?

    Has anyone seen a lisp like this? I know someone in my local user group wrote one, but I dont have his contact info. One it would come in handy, but more importantly I want to try to write a different type of routine but use that as a guide and starting point (I am new at this). All the routine did was allow the user to pick to points and it would draw a line between them, always going horizontally first. It was used to connect points in wiring schematics. Any help would be appreciated

  2. #2
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,095
    Login to Give a bone
    0

    Default Re: Lisp to draw right angle lines?

    Shawn, (my apologies if this is wrong)

    What do you want your routine to do? Can you provide the steps that you want to automate?

    Posting those steps will help the group understand what you are wanting to do.
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  3. #3
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,106
    Login to Give a bone
    0

    Default Re: Lisp to draw right angle lines?

    Like this?

    Code:
    (defun c:TwoPoints (/ lstPoint1 lstPoint2)
     (setq lstPoint1 (getpoint "\nSelect first point: ")
    	  lstPoint2 (getpoint "\nSelect Second point: ")
     )
     (command "pline" lstPoint1(list (car lstPoint2) (cadr lstPoint1)) lstPoint2 "" ) 
    )

  4. #4
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Lisp to draw right angle lines?

    ...or like this
    Code:
    (defun c:OrthoLine (/ Pkt1 Pkt2 )
      (setq Pkt1 (getpoint "Start point: ") )
      (while (setq Pkt2 (getpoint " next: ") )
        (command "._line" Pkt1 (list (car Pkt2 ) (cadr Pkt1 )) Pkt2 )
        (command )
        (setq Pkt1 Pkt2 Pkt2 nil )
      )
      (princ)
    )
    : ) Happy Computing !

    kennet

  5. #5
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Default Re: Lisp to draw right angle lines?

    this code will do it using ActiveX
    it add two commands to your system
    doline and dopline
    the doline drawing two lines
    the dopline draw it using LIGHTWEIGHTPOLYLINE
    the commands call the function myline and mypline
    I have done it this way so if in other programs you have the points and need to drawing
    the line all you need to do is call the function

    Code:
    ;;Before you can use ActiveX functions with AutoLISP,
    ;;you need to load the supporting code that enables these functions.
    ;;Issue the following function call to load ActiveX support: 
    (vl-load-com)	;This should be the fisrt line in all
    	 ;AutoLisp programs that use Activex
     
    ;;function (myline mypt1 mypt2) draw two lines
    ;;the first line go form mypt1 to the y of mypt1 and the x of mypt2
    ;;the 2nd line go form the y of mypt1 and the x of mypt2 to mypt2
    ;;the function dose not ask for the point so it can be called
    ;;from other programs
     
    (defun myline (mypt1	mypt2	 /	mypt3
    		acadObject acadDocument	 mSpace
    		myobject
    	 )
    ;;After loading the ActiveX support functions, the first step in
    ;;accessing AutoCAD objects is to establish a connection to the
    ;;AutoCAD Application object. Use the vlax-get-acad-object function
    ;;to establish this connection.
    ;;The following AutoLISP command returns the AutoCAD Application.
     
    (setq acadObject (vlax-get-acad-object))
     
    ;;Following the AutoCAD object model hierarchy, the ActiveDocument
    ;;property of the Application object leads you to a Document object.
    ;;This Document object represents the current AutoCAD drawing.
    ;;The following AutoLISP command returns the active document: 
     
    (setq acadDocument (vla-get-ActiveDocument acadObject))
     
    ;;The Document object has many properties. Access to non-graphical
    ;;objects (layers, linetypes, and groups, for example) is provided
    ;;through like-named properties such as Layers, Linetypes, and;;
    ;;Groups. To get to the graphical objects in the AutoCAD drawing,
    ;;you must access either the drawing's model space
    ;;(through the ModelSpace property) or
    ;;paper space (through the PaperSpace property).
    ;;The following AutoLISP command returns the ModelSpace 
     
    (setq mSpace (vla-get-ModelSpace acadDocument))
     
    ;;set up point three
    (setq mypt3 (list (car mypt2) (cadr mypt1) (caddr mypt1)))
    ;;add the first line
    (setq myobject (vla-addline
    	 mspace
    	 (vlax-3d-point mypt1)
    	 (vlax-3d-point mypt3)
    ) ;_ end of vla-addline
    ) ;_ end of setq
    ;;if you need to set properties such as Layers, Linetypes, and Groups for
    ;;line one do it here
     
    ;;add the 2nd line
    (setq myobject (vla-addline
    	 mspace
    	 (vlax-3d-point mypt3)
    	 (vlax-3d-point mypt2)
    ) ;_ end of vla-addline
    ) ;_ end of setq
    ;;if you need to set properties such as Layers, Linetypes, and Groups for
    ;;line two do it here
     
    ) ;_ end of defun
     
    ;;command doline
    ;;Ask for the two line point and call myline
    (defun c:doline (/ mypt1 mypt2)
    (setq mypt1 (getpoint "Enter First Point"))
    (setq mypt2 (getpoint "Enter 2ND Point" mypt1))
    (myline mypt1 mypt2)
    ) ;_ end of defun
     
     
    ;;how do it useing LIGHTWEIGHTPOLYLINE
    (defun mypline (mypt1	 mypt2 /	 myarray
    acadObject acadDocument	 mSpace
    myobject
    		)
    (setq acadObject (vlax-get-acad-object))
    (setq acadDocument (vla-get-ActiveDocument acadObject))
    (setq mSpace (vla-get-ModelSpace acadDocument))
    ;;set up point the array of points
    (setq myarray (vlax-make-safearray vlax-vbDouble '(0 . 5)))
    (vlax-safearray-put-element myarray 0 (car mypt1))
    (vlax-safearray-put-element myarray 1 (cadr mypt1))
    (vlax-safearray-put-element myarray 2 (car mypt2))
    (vlax-safearray-put-element myarray 3 (cadr mypt1))
    (vlax-safearray-put-element myarray 4 (car mypt2))
    (vlax-safearray-put-element myarray 5 (cadr mypt2))
     
    ;;add the LIGHTWEIGHTPOLYLINE
    (setq myobject (vla-addLIGHTWEIGHTPOLYLINE mspace myarray))
     
    ;;if you need to set properties such as Layers, Linetypes, and Groups for
    ;;pline do it here using myobject
     
    ) ;_ end of defun
     
    ;;command dopline do it using LIGHTWEIGHTPOLYLINE
    ;;Ask for the two line point and call myline
    (defun c:dopline (/ mypt1 mypt2)
    (setq mypt1 (getpoint "Enter First Point"))
    (setq mypt2 (getpoint "Enter 2ND Point" mypt1))
    (mypline mypt1 mypt2)
    ) ;_ end of defun
    Last edited by jwanstaett; 2005-10-15 at 07:23 PM.

  6. #6
    I could stop if I wanted to
    Join Date
    2002-02
    Location
    Kansas
    Posts
    487
    Login to Give a bone
    0

    Question Re: Lisp to draw right angle lines?

    why did you put this line in the code
    Quote Originally Posted by kennet.sjoberg
    ...or like this
    Code:
    (setq Pkt1 Pkt2 Pkt2 nil )
    kennet
    when this line in your code will set Pkt1 and Pkt2 to nill when the function exits
    Quote Originally Posted by kennet.sjoberg
    ...or like this
    Code:
    (defun c:OrthoLine (/ Pkt1 Pkt2 )
    kennet

  7. #7
    Administrator Opie's Avatar
    Join Date
    2002-01
    Location
    jUSt Here (a lot)
    Posts
    9,095
    Login to Give a bone
    0

    Default Re: Lisp to draw right angle lines?

    jwanstaett,

    He is changing the variable to nil to continue the command until the user responds with an enter command to end the routine. Setting Pkt2 to nil does not really have any effect though. If you respond to a getpoint with an enter it would return a nil, which would set Pkt2 to nil anyway.


    Code:
    (defun c:OrthoLine (/ Pkt1 Pkt2 )
      (setq Pkt1 (getpoint "Start point: ") )
      (while (setq Pkt2 (getpoint " next: ") )
        (command "._line" Pkt1 (list (car Pkt2 ) (cadr Pkt1 )) Pkt2 )
        (command )
        (setq Pkt1 Pkt2 Pkt2 nil )
      )
      (princ)
    )
    You could also add the Pkt1 to the following line to allow for the rubberband effect
    Code:
    (while (setq Pkt2 (getpoint Pkt1 " next: ") )
    If you have a technical question, please find the appropriate forum and ask it there.
    You will get a quicker response from your fellow AUGI members than if you sent it to me via a PM or email.
    jUSt

  8. #8
    AUGI Addict kennet.sjoberg's Avatar
    Join Date
    2002-05
    Posts
    1,707
    Login to Give a bone
    0

    Default Re: Lisp to draw right angle lines?

    Quote Originally Posted by jwanstaett
    why did you put this line in the code ...
    I can see that there is an answer already, thank you Richard.
    The only reason to the Pkt switch is to let the command loop and continue from the previous Pkt.

    : ) Happy Computing !

    kennet

  9. #9
    Member
    Join Date
    2005-10
    Posts
    2
    Login to Give a bone
    0

    Default Re: Lisp to draw right angle lines?

    I tried the first lisp wrote and it was perfect you guys are awesome. Someday, I will figure out how to write them!

Similar Threads

  1. Add Draw Order/Lines Merge/Lines Overwrite settings to layer properties
    By Wish List System in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2013-10-25, 01:57 AM
  2. Draw a line at a specific angle
    By matt__w in forum Revit MEP - General
    Replies: 7
    Last Post: 2010-08-20, 11:28 PM
  3. Measure Angle Between Lines
    By autocad.wishlist1734 in forum AutoCAD Wish List
    Replies: 0
    Last Post: 2007-04-02, 08:03 PM
  4. Draw a Line given 1 point and an angle
    By tany0070 in forum AutoLISP
    Replies: 7
    Last Post: 2007-03-13, 08:38 AM
  5. How do you draw gutter on an angle?
    By Richard McCarthy in forum Revit Architecture - General
    Replies: 5
    Last Post: 2004-09-14, 08:33 AM

Posting Permissions

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