+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

Thread: Node extraction

  1. #1
    Junior Member
    Computer Details
    Hari Prashanth's Computer Details
    Operating System:
    Windows XP
    Using
    AutoCAD 2007
    Join Date
    Jan 2011
    Location
    India
    Posts
    11

    Unhappy Node extraction

    Registered forum members do not see this ad.

    Hi all...
    Im using AUTOlisp to extract the coordinates out of a 2D figure to an excel file.
    Ive attached a figure for reference too.

    I've to follow some conditions regarding the figures...
    1. The figure must be in posotive quardrant only.
    2. The coordinate extraction must always start from the origin .ie (0,0).
    3. Proceed along the line
    4. Proceed along the pentagon
    5. And finish at the same point where the line meets the figure or one node before that.

    Here s procedure i m following...
    1.Ill draw the figure.
    2.Divide it into many nodes with 'divide' command.
    3.Load the following lisp to extract the coordinates in a spreadsheet.

    Ive attached the LISP coding and the sample figure.
    Any suggestions would be helpful. Pls help.
    Attached Files

  2. #2
    Forum Deity Tharwat's Avatar
    Discipline
    Mechanical
    Tharwat's Discipline Details
    Occupation
    MEP AutoCAD Draftsman
    Discipline
    Mechanical
    Using
    AutoCAD 2014
    Join Date
    Oct 2009
    Location
    Lives in Abu Dhabi
    Posts
    2,624

    Default

    Codes removed due to ignorance !!

    Tharwat
    Last edited by Tharwat; 15th Feb 2011 at 05:25 am.

  3. #3
    Full Member Smirnoff's Avatar
    Using
    AutoCAD 2011
    Join Date
    Feb 2011
    Location
    Riga, Latvia
    Posts
    57

    Default

    It looks as student home work. Are you sure that your professor does not participate in this forum?

    Ok. some help for you. But not full of course. You don't need to use DIVIDE command but extract vertexes (nodes) of line and polyline (pentagon). There is sample code:

    Code:
    (defun c:test2(/ cLn cPl lLst pLst)
     (if
       (and
        (setq cLn(entsel "\nPick line > "))
        (setq cPl(entsel "\nPick pentagon > "))
        ); and
       (progn
         (setq cLn(entget(car cLn)) ; get DXF-codes of line
    	   cPl(entget(car cPl)) ; get DXF-codes of polyline
    	   lLst(list		; extract list of ((start pt)(end pt)) for line
    		 (cdr(assoc 10 cLn)) 
    		 (cdr(assoc 11 cLn))
    		 ); end list
    	   pLst(mapcar 'cdr	; extract list ((vertex1)(vertex2)...) for polyline
    		       (vl-remove-if-not
    			 '(lambda(i)(= 10(car i)))cPl))
    	   ); end pLst
         ); end progn
       ); end if
      (list lLst pLst) ; returns ((list 1)(list 2))
      ); end of c:test2
    Now you should to think, how to sort that coordinates to write it to text file in right order.
    Simply AutoLISP maniac

  4. #4
    Junior Member
    Computer Details
    Hari Prashanth's Computer Details
    Operating System:
    Windows XP
    Using
    AutoCAD 2007
    Join Date
    Jan 2011
    Location
    India
    Posts
    11

    Default

    Sir Smirnoff,
    Your code was very helpful. Sorry i m new to autoCAD and autoLISP. This ain't my field of study too. This is a part of my project 'developin a CNC machine'. Ive understood most of the parts from comments which u ve incuded. Thank u for that. When i try to save it in a TXT file or CSV file it appears empty. Ive enclosed the code below. Pls help me out with this.

    (defun c:test2(/ cLn cPl lLst pLst fn f )
    (if
    (and
    (setq cLn(entsel "\nPick line > "))
    (setq cPl(entsel "\nPick pentagon > "))
    ); and
    (progn
    (setq cLn(entget(car cLn)) ; get DXF-codes of line
    cPl(entget(car cPl)) ; get DXF-codes of polyline
    lLst(list ; extract list of ((start pt)(end pt)) for line
    (cdr(assoc 10 cLn))
    (cdr(assoc 11 cLn))
    ); end list
    pLst(mapcar 'cdr ; extract list ((vertex1)(vertex2)...) for polyline
    (vl-remove-if-not
    '(lambda(i)(= 10(car i)))cPl))
    ); end pLst
    ); end progn
    ); end if
    (list lLst pLst) ; returns ((list 1)(list 2))


    (if (not (setq fn (getfiled "Export to file" (getvar "dwgprefix") "csv" 1)))
    (progn (alert "No file selected!") (quit))
    )

    (setq f (open fn "w"))
    (princ (strcat (rtos (car llst)) "," (rtos (cadr llst))"\n") f)
    (close f)

    (setq f (open fn "w"))
    (princ (strcat (rtos (car plst)) "," (rtos (cadr plst))"\n") f)
    (close f)

    (alert (strcat "Finish export points to file: " fn))
    ); end of c:test2

  5. #5
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,090

    Default

    Quote Originally Posted by Hari Prashanth View Post
    Sir Smirnoff,
    Your code was very helpful. Sorry i m new to autoCAD and autoLISP. This ain't my field of study too. This is a part of my project 'developin a CNC machine'. Ive understood most of the parts from comments which u ve incuded. Thank u for that. When i try to save it in a TXT file or CSV file it appears empty. Ive enclosed the code below. Pls help me out with this.
    not sure how you wanted your output to look,

    Code:
     
    (defun
       c:test2  (/ cLn cPl lLst pLst fn f)
      (if (and
            (setq cLn (entsel "\nPick line > "))
            (setq cPl (entsel "\nPick pentagon > "))) ; and
        (progn
          (setq
            cLn  (entget (car cLn))         ; get DXF-codes of line
            cPl  (entget (car cPl))         ; get DXF-codes of polyline
            lLst (list                      ; extract list of ((start pt)(end pt)) for line
                   (cdr (assoc 10 cLn))
                   (cdr (assoc 11 cLn)))    ; end list
            pLst (mapcar
                   'cdr                     ; extract list ((vertex1)(vertex2)...) for polyline
                   (vl-remove-if-not '(lambda (i) (= 10 (car i))) cPl)))
                                            ; end pLst
          )                                 ; end progn
        )                                   ; end if
      (list lLst pLst)                      ; returns ((list 1)(list 2))
      (if (not
            (setq
              fn
               (getfiled "Export to file" (getvar "dwgprefix") "csv" 1)))
        (progn (alert "No file selected!") (quit)))
      (setq f (open fn "a"))
      (write-line
     (strcat
       (vl-princ-to-string (car llst))
       ","
       (vl-princ-to-string (cadr llst)))
     f)
    (write-line
     (strcat
       (vl-princ-to-string (car plst))
       ","
       (vl-princ-to-string (cadr plst)))
     f)
      (close f)
      (alert (strcat "Finish export points to file: " fn)))

    the result will look like this
    two columns
    Column A
    (-122.807 179.928 0.0)
    (-4.48415 271.639 0.0)
    (118.262 191.53)
    (167.471 248.987)
    Column B
    (-122.807 179.928 0.0)
    (-4.48415 271.639 0.0)
    (118.262 191.53)
    (167.471 248.987)

    I change this
    (open fn "w")
    to this
    (open fn "a"))

    w- Open for writing. If filename does not exist, a new file is created and opened. If filename already exists,
    its existing data is overwritten.
    Data passed to an open file is not actually written until the file is closed with the close function.

    while

    a- Open for appending. If filename does not exist, a new file is created and opened. If filename already exists,
    it is opened and the pointer is positioned at the end of the existing data, so new data you write to the file is appended to the existing data.




    Hope this helps

  6. #6
    Junior Member
    Computer Details
    Hari Prashanth's Computer Details
    Operating System:
    Windows XP
    Using
    AutoCAD 2007
    Join Date
    Jan 2011
    Location
    India
    Posts
    11

    Default

    Sir pBE,
    Ive understood about write and append modes. But the code didn't print as u told. It jus prints the two end points of the line and only one vertex of the pentagon. Pls help.

  7. #7
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,090

    Default

    Quote Originally Posted by Hari Prashanth View Post
    Sir pBE,
    Ive understood about write and append modes. But the code didn't print as u told. It jus prints the two end points of the line and only one vertex of the pentagon. Pls help.
    Ooops

    you're right.
    The thing that gets me is
    for the points of your polygon you still want it as two columns, anyway..

    Code:
     
    (defun
       c:test2  (/ cLn cPl lLst pLst fn f)
      (if (and
            (setq cLn (entsel "\nPick line > "))
            (setq cPl (entsel "\nPick pentagon > "))) ; and
        (progn
          (setq
            cLn  (entget (car cLn))         ; get DXF-codes of line
            cPl  (entget (car cPl))         ; get DXF-codes of polyline
            lLst (list                      ; extract list of ((start pt)(end pt)) for line
                   (cdr (assoc 10 cLn))
                   (cdr (assoc 11 cLn)))    ; end list
            pLst (mapcar
                   'cdr                     ; extract list ((vertex1)(vertex2)...) for polyline
                   (vl-remove-if-not '(lambda (i) (= 10 (car i))) cPl)))
                                            ; end pLst
          )                                 ; end progn
        )                                   ; end if
      (list lLst pLst)                      ; returns ((list 1)(list 2))
      (if (not
            (setq
              fn
               (getfiled "Export to file" (getvar "dwgprefix") "csv" 1)))
        (progn (alert "No file selected!") (quit)))
      (setq f (open fn "a"))
      (write-line
     (strcat
       (vl-princ-to-string (car llst))
       ","
       (vl-princ-to-string (cadr llst)))
     f)
    (repeat (/ (length plst) 2)
    (write-line
    (strcat
    (vl-princ-to-string (car plst))
    ","
    (vl-princ-to-string (cadr plst)))
    f)
    (setq plst (cdr (member (cadr plst) plst )))
    )
     
      (close f)
      (alert (strcat "Finish export points to file: " fn)))
    Result
    (17.735 225.294 0.0) (80.5574 286.498 0.0)<-- for line (assoc 10/11)
    (186.963 272.374) (139.364 271.642)<-- for polygon (6 points)(six sides)
    (116.199 230.055) (140.631 189.199)
    (188.23 189.931) (211.396 231.517)

    but if you want single column for your polygon

    Code:
     
    (defun
       c:test2  (/ cLn cPl lLst pLst fn f)
      (if (and
            (setq cLn (entsel "\nPick line > "))
            (setq cPl (entsel "\nPick pentagon > "))) ; and
        (progn
          (setq
            cLn  (entget (car cLn))         ; get DXF-codes of line
            cPl  (entget (car cPl))         ; get DXF-codes of polyline
            lLst (list                      ; extract list of ((start pt)(end pt)) for line
                   (cdr (assoc 10 cLn))
                   (cdr (assoc 11 cLn)))    ; end list
            pLst (mapcar
                   'cdr                     ; extract list ((vertex1)(vertex2)...) for polyline
                   (vl-remove-if-not '(lambda (i) (= 10 (car i))) cPl)))
                                            ; end pLst
          )                                 ; end progn
        )                                   ; end if
      (list lLst pLst)                      ; returns ((list 1)(list 2))
      (if (not
            (setq
              fn
               (getfiled "Export to file" (getvar "dwgprefix") "csv" 1)))
        (progn (alert "No file selected!") (quit)))
      (setq f (open fn "a"))
      (write-line
     (strcat
       (vl-princ-to-string (car llst))
       ","
       (vl-princ-to-string (cadr llst)))
     f)
    (repeat (length plst)
    (write-line
       (vl-princ-to-string (car plst))
     f)
      (setq plst (cdr plst))
      )
      
      (close f)
      (alert (strcat "Finish export points to file: " fn)))
    Result
    (17.735 225.294 0.0) (80.5574 286.498 0.0)<-- for line (assoc 10/11)
    (186.963 272.374) <-- for polygon (6 points)(six sides)
    (139.364 271.642)
    (116.199 230.055)
    (140.631 189.199)
    (188.23 189.931)
    (211.396 231.517)
    Last edited by pBe; 15th Feb 2011 at 01:18 pm.

  8. #8
    Junior Member
    Computer Details
    Hari Prashanth's Computer Details
    Operating System:
    Windows XP
    Using
    AutoCAD 2007
    Join Date
    Jan 2011
    Location
    India
    Posts
    11

    Default

    Thanks a lot Sir pBe, your code definately helped.
    This is ok when i extract points from regular shapes. What if i try to extract coor from an arc or an eclipse segment or an irregular arc.... So i gotta divide the arc into nodes and extract at regular intervals. That is what i ve been asking at the fisrt place. How could i do so? Thanks in advance.

  9. #9
    Forum Deity pBe's Avatar
    Computer Details
    pBe's Computer Details
    Operating System:
    Windows XP
    Discipline
    Construction
    pBe's Discipline Details
    Discipline
    Construction
    Details
    Camp Construction planning and details
    Using
    AutoCAD 2009
    Join Date
    Apr 2010
    Posts
    2,090

    Default

    Quote Originally Posted by Hari Prashanth View Post
    Thanks a lot Sir pBe, your code definately helped.
    This is ok when i extract points from regular shapes. What if i try to extract coor from an arc or an eclipse segment or an irregular arc.... So i gotta divide the arc into nodes and extract at regular intervals. That is what i ve been asking at the fisrt place. How could i do so? Thanks in advance.
    you dont really need to divide the object with nodes to get the points within an arc.
    look at this sample, given a constant interval say at every 10

    Code:
     
    (defun test (val / objts objt_length strt_pt pts valA)
       (vl-load-com)
        (setq objts (vlax-ename->vla-object (car (entsel))))
        (setq objt_length (vlax-curve-getDistAtParam objts
                          (vlax-curve-getEndParam objts)))
                    (setq strt_pt (vlax-curve-getStartPoint objts))
        (setq pts (list strt_pt) valA val)
      (repeat (fix (/ objt_length val))
      (setq pts (cons (vlax-curve-getPointAtDist objts val) pts)
                          val (+ val valA))
                       )
        (setq pts (reverse (cons (vlax-curve-getendpoint objts) pts)))
        (foreach pt pts
                       (print pt)
                      )
      (princ)
    )
    USAGE:
    command: (test 10)<---- where 10 is your interval value
    command: Select object:

    Result:
    (242.391 222.255 0.0)<---startpoint
    (233.314 226.444 0.0)<--- pts at 10.00 interval
    (223.933 229.9 0.0)
    (214.308 232.602 0.0)
    (204.498 234.532 0.0)
    (194.567 235.678 0.0)
    (184.576 236.033 0.0)
    (174.588 235.595 0.0)
    (164.666 234.366 0.0)
    (154.874 232.355 0.0)<-- pts at 10.00 interval
    (148.552 230.617 0.0)<-- remainder to endpoint

    Hope this helps
    And... stop calling me sir

  10. #10
    Junior Member
    Computer Details
    Hari Prashanth's Computer Details
    Operating System:
    Windows XP
    Using
    AutoCAD 2007
    Join Date
    Jan 2011
    Location
    India
    Posts
    11

    Default

    Registered forum members do not see this ad.

    Well thanks a lot. That solves my querry. Sorry for what i m gonna ask hereafter. Can i get the code for printing those values in an excel or CSV file. When i tried it prints only two values. And... Instead of extracting it as a point itself in this frm ( , ) can it extract 'x' values in one column and 'y' in another column.

    This is the code i ve been using...
    (defun tst5 (val / objts objt_length strt_pt pts valA fn f)
    (vl-load-com)
    (setq objts (vlax-ename->vla-object (car (entsel))))
    (setq objt_length (vlax-curve-getDistAtParam objts
    (vlax-curve-getEndParam objts)))
    (setq strt_pt (vlax-curve-getStartPoint objts))
    (setq pts (list strt_pt) valA val)
    (repeat (fix (/ objt_length val))
    (setq pts (cons (vlax-curve-getPointAtDist objts val) pts)
    val (+ val valA))
    )
    (setq pts (reverse (cons (vlax-curve-getendpoint objts) pts)))

    (setq fn(getfiled "Export to file" (getvar "dwgprefix") "csv" 1)))
    (progn (alert "No file selected!") (quit)))

    (foreach pt pts

    (if (not

    (setq f (open fn "a"))
    (write-line
    (strcat
    (vl-princ-to-string (car pt))
    ","
    (vl-princ-to-string (cadr pt)))
    f)

    (close f)
    (alert (strcat "Finish export points to file: " fn)))

Similar Threads

  1. Node placement
    By kilc6887 in forum AutoCAD General
    Replies: 7
    Last Post: 20th Dec 2010, 08:05 pm
  2. Node Size
    By Moe` in forum AutoCAD Beginners' Area
    Replies: 4
    Last Post: 14th Jun 2010, 08:22 pm
  3. How to delete an action node
    By GliderRider in forum AutoCAD Drawing Management & Output
    Replies: 2
    Last Post: 19th Feb 2009, 06:32 pm
  4. Polyline node commands
    By WILL.R in forum AutoCAD 2D Drafting, Object Properties & Interface
    Replies: 7
    Last Post: 12th Dec 2008, 01:08 pm
  5. Node to Excel
    By cadguy_tw in forum AutoLISP, Visual LISP & DCL
    Replies: 5
    Last Post: 6th Sep 2005, 07:50 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