Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Insert block using coordinates in a txt file

  1. #1
    All AUGI, all the time
    Join Date
    2000-12
    Location
    Blue Springs, MO
    Posts
    658
    Login to Give a bone
    0

    Default Insert block using coordinates in a txt file

    I have a text file with x & y coordinates and I need to insert a block for a column at each coordinate. I thought of writing a script file but quickly changed my mind when I found out there were over 100 coordinates. My next thought was lisp but I'm lisp challenged when it comes to accessing outside data. Can anyone give me some direction and to how I go about this, or better yet, a lisp or portion of one that can get me started?

    Thanks

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

    Default Re: Insert block using coordinates in a txt file

    Look into OPEN, WRITE-LINE, READ-LINE, and CLOSE.

    Also post an example text file and block.

  3. #3
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    Quote Originally Posted by jmctamney
    I have a text file with x & y coordinates and I need to insert a block for a column at each coordinate. I thought of writing a script file but quickly changed my mind when I found out there were over 100 coordinates. My next thought was lisp but I'm lisp challenged when it comes to accessing outside data. Can anyone give me some direction and to how I go about this, or better yet, a lisp or portion of one that can get me started?

    Thanks
    Hi,

    Can you post a sample of the data you are working with? It would be easier if we knew how the data is layed out. IE is it comma delimited, space delimited, etc, and does it include the block name.

  4. #4
    All AUGI, all the time
    Join Date
    2000-12
    Location
    Blue Springs, MO
    Posts
    658
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    as it is right now, it's a .txt file with x&y coordinates, each on a single line separated by a comma. I don't know yet what I'll use for my block. I'm trying to coordinate column locations based on x,y coordinates provided by the architect

  5. #5
    AUGI Addict .T.'s Avatar
    Join Date
    2000-12
    Location
    Lost
    Posts
    1,473
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    Quote Originally Posted by jmctamney
    as it is right now, it's a .txt file with x&y coordinates, each on a single line separated by a comma. I don't know yet what I'll use for my block. I'm trying to coordinate column locations based on x,y coordinates provided by the architect
    You might be able to modify T.Willey's code from THIS THREAD to do what you want. Have a looka at it, then let us know if you need help doing that.

  6. #6
    I could stop if I wanted to
    Join Date
    2015-08
    Posts
    263
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    Quote Originally Posted by jmctamney
    I have a text file with x & y coordinates and I need to insert a block for a column at each coordinate. I thought of writing a script file but quickly changed my mind when I found out there were over 100 coordinates. My next thought was lisp but I'm lisp challenged when it comes to accessing outside data. Can anyone give me some direction and to how I go about this, or better yet, a lisp or portion of one that can get me started?

    Thanks
    Hi,

    The following piece of code will read the text file and insert the block as per the coordinates. All you need to substitute is the input file name with path and your block name. If the block name is not in the drawing, give path and file name for the wblock (eg "c:\\path\blockname.dwg")

    Code:
    (defun c:insertBlocks (/ txtFile xyData expertVar attreqVar)
    (setq expertVar (getvar "expert"))
    (setq attreqVar (getvar "attreq"))
    (setvar "expert" 2)
    (setvar "attreq" 0)
      (setq txtFile (open "c:\\cad\\textfile.txt" "r")) ; give the path & file name of x,y data
     (while (setq xyData (read-line txtFile))
       (command "-insert" "blockName" xyData "1" "1" "0") ; substitute blockName with your block
       )
      (close txtFile)
    (setvar "expert" expertVar)
    (setvar "attreq" attreqVar)
      (princ)
    )
    Regards,
    Abdul Huck

  7. #7
    Member
    Join Date
    2014-06
    Posts
    2
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    Hi Abdul,
    Thanks this is great, I wonder if you or anyone here has an idea on how to make the .txt file a relative path of the current dwg file.
    i.e. Both the txt and the dwg are in the same folder and I have the dwg open in AutoCAD and active.
    If I were using old dos the path would be .\file.txt (which I tried but got the ; error: bad argument type: FILE nil)
    Or would it be easier to add a user input to point to the file via a browse dialog and if so can you point me in the right direction.

    Here is my current attempt:

    Code:
    (defun c:iPost (/ txtFile xyData expertVar attreqVar)
    (setq expertVar (getvar "expert"))
    (setq attreqVar (getvar "attreq"))
    (setvar "expert" 2)
    (setvar "attreq" 0)
      (setq txtFile (open ".\Coords.txt" "r")) ; Path
     (while (setq xyData (read-line txtFile))
       (command "-insert" "post" xyData "1" "1" "0") ; BlockName
       )
      (close txtFile)
    (setvar "expert" expertVar)
    (setvar "attreq" attreqVar)
      (princ)
    )
    May thanks for your assistance,
    Chris

  8. #8
    Member
    Join Date
    2008-01
    Posts
    26
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    1. Pointsin.lsp (Google it) is a good open source example of a program that does this with plenty of options.

    2. To your latest question, here's an idea of where you need to go:
    (setq txtFileName (findfile "coords.txt"))
    (setq txtFile (open txtFileName "r"))

    or to be more specific

    (setq txtFileName (strcat (getvar "dwgprefix") "coords.txt")))
    (setq txtFile (open txtFileName "r"))

    Or to browse (this would have to be tweaked for pre-R14)

    (setq txtFileName (GETFILED "Points data file" (STRCAT (GETVAR "dwgprefix") (getvar "dwgname") "" 0))
    (setq txtFile (open txtFileName "r"))


    Tom
    Last edited by tom.haws; 2017-02-05 at 08:56 PM.

  9. #9
    Member
    Join Date
    2014-06
    Posts
    2
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    Thanks Tom that was enough information for me to fabri-cobble something together. Here is what I ended up with for anyone else that happens along this thread.

    Code:
    (defun c:iBlock (/ txtFile xyData expertVar attreqVar)
    (setq expertVar (getvar "expert"))
    (setq attreqVar (getvar "attreq"))
    (setvar "expert" 2)
    (setvar "attreq" 0)
      (setq txtFileName (getfiled "Select a Coordinate File" "c:/" "txt" 16))
      (setq txtFile (open txtFileName "r"))
     (while (setq xyData (read-line txtFile))
       (command "-insert" "module" xyData "1" "1" "0") ; substitute "module" with your block "name". If the block name is not in the drawing, give path and file name to the Block (eg "c:\\path\\blockname.dwg")
       )
      (close txtFile)
    (setvar "expert" expertVar)
    (setvar "attreq" attreqVar)
      (princ)
    )
    I have 2 more challenges to overcome If someone could point me in the right direction that would be great.

    1st) I would like the lisp to change the attribute value embedded in each of the blocks that are being inserted. The attribute tag is "NAME" and the default is A1. Ideally it would sequentially name each block i.e A1,A2,A3 etc.. without manual input from the user.
    2nd) The block is dynamic with 2 Parameters XWIDTH and YWIDTH with stretch actions attached to them. Ideally I would like the list that controls the insertion point to also contain dimension data for the 2 Parameters/stretch actions. Thus adjusting the dynamic block while inserting from the list.
    I imagine the list format like this
    X,Y xwidth,ywidth
    120,120 24,20
    Thus inserting the block at x120 and y120 with the dimensions of 24x20
    But I am open to any formatting that would work.

    This is starting to grow past what this thread is intended for, let me know if this needs it's own thread.

    Many thanks for the community help.. truly outstanding.

    Chris

  10. #10
    Member
    Join Date
    2008-01
    Posts
    26
    Login to Give a bone
    0

    Default Re: Insert block using coordinates in a txt file

    I could probably add this functionality and shoehorn what you want into POINTSIN.LSP to make a new application or an extension of POINTSIN.

Page 1 of 2 12 LastLast

Similar Threads

  1. Insert a Tool Palette Block While Editing a Block or Xref.
    By Wish List System in forum AutoCAD Wish List
    Replies: 1
    Last Post: 2013-10-07, 04:53 PM
  2. HELP......With Insert Block Lisp From Excel File
    By CADdancer in forum AutoLISP
    Replies: 1
    Last Post: 2013-06-25, 08:47 PM
  3. How to insert a DWG file as a block
    By Coolmo in forum Dot Net API
    Replies: 8
    Last Post: 2010-06-22, 01:36 AM
  4. Insert list of block names in a txt file
    By aharris in forum AutoLISP
    Replies: 6
    Last Post: 2006-11-14, 10:35 PM
  5. Replies: 19
    Last Post: 2006-03-14, 05:06 PM

Posting Permissions

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