Results 1 to 6 of 6

Thread: Using the inters function in Lisp

  1. #1
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Using the inters function in Lisp

    I am having trouble finding the intersection between two lines. I have searched the help files and also searched here on Augi and couldn't find much. I have all four points needed to find the intersection. In the code below at the bottom where i am finding the interesection there is a commented line of code. This line of code returns the correct intersection point but gives me an error and terminates the program. The uncommented line of code (the on ewithout the ;; in front of it) works without any errors, but does not return the correct intersection point between the two lines. Any help would be appreciated.

    An Economizer module is just a rectangle of any width and height. I have been using one with an x dimension of 80 and a y dimension of 120.
    Code:
    (defun C:Econo ()
      (setq old_osnap(getvar "osmode"))
      ;;Getting Upper right Hand corner of Economizer module
      (setq pnt1 (getpoint "\nSelect the upper right hand corner of the Economizer Section: \n"))
      ;;Getting Lower Left Hand corner of Economizer module
      (setq pnt2 (getcorner pnt1 "\nSelect the lower left hand corner of the Economizer Section: \n"))
      (setvar "osmode" 0)
      ;;Getting Angle the economizer will be placed at
      (setq ang (getreal "Enter angle of economizer <30 or 45>:\n"))
      ;;Getting Center point of Economizer module.
      (setq cpnt (list(/(+(car pnt1)(car pnt2))2)(/(+(cadr pnt1)(cadr pnt2))2)))
      ;;Second point from center of module at the angle specified by the user.
      (setq cpnt1 (polar cpnt (dtr ang)3))
    ;;Getting the boudary of the economizer module
      (setq bndry1 (polar pnt2 (dtr 90) (-(cadr pnt1)(cadr pnt2))))
      (setq bndry2 (polar pnt1 (dtr 270) (-(cadr pnt1)(cadr pnt2))))
      
      ;;Finding the intersection of where the center point would cross the first point selected.
      ;;(setq inters1 (inters (car cpnt) (cadr cpnt) (car pnt1) (cadr pnt1)))
      (setq inters1 (inters cpnt cpnt1 pnt1 bndry2))
      (setvar "osmode" old_osnap)
    )
    Last edited by Lions60; 2007-07-06 at 07:32 PM.

  2. #2
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Using the inters function in Lisp

    I also tried using the code below and it works without errors but does not return the correct intersection between a line at either a 45 degree angle or a 30 degree angle from the center of the rectangle.

    Code:
    (setq inters1 (inters (list(car cpnt) (cadr cpnt)) (list(car cpnt1) (cadr cpnt1)) (list(car pnt1) (cadr pnt1)) (list(car bndry2) (cadr bndry2))nil))

  3. #3
    Active Member pferreira's Avatar
    Join Date
    2006-06
    Location
    Lisbon, Portugal
    Posts
    88
    Login to Give a bone
    0

    Default Re: Using the inters function in Lisp

    Hello i have been trying to see what was wrong but i couldn't´t find anything wrong, the only thing that could be missing was the print to the command line of the coordinates.
    Look here!
    Code:
    (defun C:Econo ()
      (setq old_osnap(getvar "osmode"))
      ;;Getting Upper right Hand corner of Economizer module
      (setq pnt1 (getpoint "nSelect the upper right hand corner of the Economizer Section: n"))
      ;;Getting Lower Left Hand corner of Economizer module
      (setq pnt2 (getcorner pnt1 "nSelect the lower left hand corner of the Economizer Section: n"))
      (setvar "osmode" 0)
      ;;Getting Angle the economizer will be placed at
      (setq ang (getreal "Enter angle of economizer <30 or 45>:n"))
      ;;Getting Center point of Economizer module.
      (setq cpnt (list(/(+(car pnt1)(car pnt2))2)(/(+(cadr pnt1)(cadr pnt2))2)))
      ;;Second point from center of module at the angle specified by the user.
      (setq cpnt1 (polar cpnt (dtr ang) 3))
    ;;Getting the boudary of the economizer module
      (setq bndry1 (polar pnt2 (dtr 90) (-(cadr pnt1)(cadr pnt2))))
      (setq bndry2 (polar pnt1 (dtr 270) (-(cadr pnt1)(cadr pnt2))))
      
      ;;Finding the intersection of where the center point would cross the first point selected.
      ;;(setq inters1 (inters (car cpnt) (cadr cpnt) (car pnt1) (cadr pnt1)))
      (setq inters1 (inters cpnt cpnt1 pnt1 bndry2))
      (vl-cmdf "pline" cpnt cpnt1 "")
      (vl-cmdf "pline" pnt1 bndry2 "")
      (princ inters1)
      (setvar "osmode" old_osnap)
      (princ);;exit
    )
    
    (defun dtr (numberOfDegrees)
      (* pi (/ numberOfDegrees 180.0))
    )
    Best Regards

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

    Default Re: Using the inters function in Lisp

    The intersectwith method of a line can also get the intersection of two lines objects.

    Code:
    (defun C:INTX (/ objLine1 objLine2)
     (setq objLine1 (vlax-ename->vla-object (car (entsel "\nSelect first line: ")))
           objLine2 (vlax-ename->vla-object (car (entsel "\nSelect second line: ")))
     )
     (vlax-invoke objLine1 "intersectwith" objLine2 0)
    )

  5. #5
    I could stop if I wanted to
    Join Date
    2003-11
    Posts
    277
    Login to Give a bone
    0

    Default Re: Using the inters function in Lisp

    Hi Lions60,
    Test this code
    Code:
    (defun dtr (a)
      (* pi (/ a 180.0))
      )
    
    (defun C:Econo (/ ang bndry1 bndry2 coord cpnt cpnt1 el1 el2 old_osnap pnt1 pnt2 vevo1 vevo2)
      (setq old_osnap(getvar "osmode"))
      (setq pnt1 (getpoint "\nSelect the upper right hand corner of the Economizer Section: \n"))
      ; (4.26591 25.9316 0.0) 
      (setq pnt2 (getcorner pnt1 "\nSelect the lower left hand corner of the Economizer Section: \n"))
      ; (35.7619 3.30618 0.0) 
      (setvar "osmode" 0)
      (setq ang (getreal "Enter angle of economizer <30 or 45>:\n"))
      ; 30.0
      (setq cpnt (list(/ (+(car pnt1)(car pnt2))2)(/ (+(cadr pnt1)(cadr pnt2))2)))
      ; (20.0139 14.6189) 
      (setq cpnt1 (polar cpnt (dtr ang) 3))
      ; (22.612 16.1189)
      (setq bndry1 (polar pnt2 (dtr 90) (-(cadr pnt1)(cadr pnt2))))
      ; (35.7619 25.9316 0.0)
      (setq bndry2 (polar pnt1 (dtr 270) (-(cadr pnt1)(cadr pnt2))))
      ; (4.26591 3.30618 0.0)
      (command "_line" cpnt cpnt1 "")
      (setq el1 (entlast))
      (setq vevo1 (vlax-ename->vla-object el1))
      (command "_line" pnt1 bndry2 "")
      (setq el2 (entlast))
      (setq vevo2 (vlax-ename->vla-object el2))
      (setq coord (vlax-invoke vevo1 'IntersectWith vevo2 1))
      (alert (strcat "\nThis intersection at"
    		 "\n"
    		 "\n"
    		 "(" (rtos (car coord))
    		 ","
    		 (rtos (cadr coord))
    		 ","
    		 (rtos (caddr coord))
    		 ")")))
      ;(command "_erase" el1 el2 "")  
      ;(setq inters1 (inters cpnt cpnt1 pnt1 bndry2))
      (setvar "osmode" old_osnap)
      )

  6. #6
    I could stop if I wanted to
    Join Date
    2006-07
    Posts
    233
    Login to Give a bone
    0

    Default Re: Using the inters function in Lisp

    Thanks everyone for their help. I tried the methods posted and they all returned the same value , but where drawing the line from a different point than expected. I figured the problem out to be that i was turning my osnaps back on to soon so instead of drawing a line from the intended point it was snapping to an endpoint.

Similar Threads

  1. New function in ObjectARX for LISP
    By erick_19_hk266024 in forum ARX
    Replies: 1
    Last Post: 2013-08-26, 12:46 PM
  2. My first lisp function...
    By JLHConsulting in forum AutoLISP
    Replies: 19
    Last Post: 2010-06-11, 06:06 PM
  3. changevpsettings .Net to LISP function
    By peter in forum Dot Net API
    Replies: 3
    Last Post: 2009-12-11, 03:44 PM
  4. Replies: 7
    Last Post: 2009-11-02, 05:38 AM
  5. Arrow OR Tab Key Function In Lisp?
    By omorah in forum AutoCAD Customization
    Replies: 2
    Last Post: 2008-11-20, 02:59 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
  •