+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
  1. #1
    Senior Member
    Computer Details
    numberOCD's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP EliteBook 8770w
    RAM:
    16Gb
    Using
    MEP 2014
    Join Date
    Apr 2010
    Location
    Chicago/New York USA
    Posts
    164

    Default Insert Blocks off of List with Attributes and Rotate the Blocks when inserted

    Registered forum members do not see this ad.

    Good Morning,
    I am brand new to AutoLISP and am not picking it up quite as well.
    I'm trying to make a LISP that will insert around 1500 blocks at designated coordinates off a list I will make in Excel (or can transfer to a txt). The excel list will have X,Y coordinates, an angle of rotation, and 2 or 3 attributes.

    This LISP will not be for a long time use, it's mainly to get a large insertion completed for editing as construction comes along, so I only need to make it for functional purpose. If someone can guide me better in how to extract the information from the list into the LISP, that's the main thing I'm having trouble picking up.

    Thanks for any help!

  2. #2
    Senior Member lrm's Avatar
    Computer Details
    lrm's Computer Details
    Operating System:
    Windows 7 64-bit
    RAM:
    16 GB
    Discipline
    Education
    lrm's Discipline Details
    Occupation
    Teacher, AEC and mechanical
    Discipline
    Education
    Details
    Civil and Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jan 2010
    Location
    Massachusetts, USA
    Posts
    349

    Default Consider a script instead of LISP

    It might be easier to use a script to add blocks to an AutoCAD drawing if your data is coming from an Excel worksheet. For example, assume your Excel file looks something like the example below with your data in columns B through G.



    Enter the following in cell A2 using the Excel Concatenate function to create the command to add a block. It is important to use spaces as noted to force the command to go on to the next argument when it is executed. Note that there is one space before the 1 (for scale) and two spaces after it. Since an Enter cannot be included in this sequence we will uses @@@ as a place holder for it.


    Use fill down to create the insert commands for all the data.

    Copy Column A from row 2 to the last row (cell A4 in my example) to the clipboard.

    Open MS Word and paste as text.

    Use Replace and replace the text @@@ with ^p . This will place the second attribute value on a new line providing an Enter input to the command.

    Save the file as a .txt file.

    Change the file name extension to .scr . The filename should be something like: filename.scr

    In AutoCAD enter the Script command and select the .scr file. This should add multiple blocks at the specified location and angle.

  3. #3
    Senior Member
    Using
    not specified
    Join Date
    Apr 2014
    Posts
    105

    Default

    You can use this routine to get information from text file. With A.txt is file and L is the result list. The item's type of L is String.
    Code:
    (setq L nil
          file (open "A.txt" "r"))
    (while (setq line (read-line file))
      (setq line (mapcar 'vl-princ-to-string (read (strcat "(" line ")")))
    	L (append L (list line)))
    )
    (close file)
    Using Tapatalk

  4. #4
    Luminous Being
    Using
    Civil 3D 2016
    Join Date
    Dec 2005
    Location
    GEELONG AUSTRALIA
    Posts
    9,902

    Default

    Irm maybe also rather than adding the Word step wrap the attribute in quotes "Apples" "Banannas". Pasting to Word need to make sure save as a TEXT file with .scr file extension, Word can add hidden characters.

    Nice clear explanation, well done.
    A man who never made mistakes never made anything

  5. #5
    Senior Member lrm's Avatar
    Computer Details
    lrm's Computer Details
    Operating System:
    Windows 7 64-bit
    RAM:
    16 GB
    Discipline
    Education
    lrm's Discipline Details
    Occupation
    Teacher, AEC and mechanical
    Discipline
    Education
    Details
    Civil and Mechanical
    Using
    AutoCAD 2014
    Join Date
    Jan 2010
    Location
    Massachusetts, USA
    Posts
    349

    Default

    BIGAL, The text string:

    -insert MyBlock 12.34,20.5 1 30 "Apples" "Bananas"

    will assign "Apples" "Bananas" to the first attribute of MyBlock. What syntax should be used to get an Enter key between the two values so that Apples is assigned to the first attribute and Bananas to the second attribute? My substitution of ^p added the Return key which did this. It would be cleaner to not have to do the substitution. Thank you.

  6. #6
    Senior Member
    Computer Details
    numberOCD's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP EliteBook 8770w
    RAM:
    16Gb
    Using
    MEP 2014
    Join Date
    Apr 2010
    Location
    Chicago/New York USA
    Posts
    164

    Default

    Irm,
    This is the kind of method I've been looking for. I used to have a similar idea for drawing polylines with varying y coordinates and increasing x by one unit (5 feet) and I would paste that list into the command line. This remedy will definitely save me a huge deal of time for this task.

    Thanks a bunch!

  7. #7
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,534

    Default

    Or maybe use autolisp syntax :
    Attached Images
    Last edited by David Bethel; 15th Jul 2014 at 06:08 pm. Reason: Wrong Scale / Angle order
    R12 (Dos) - A2K

  8. #8
    Senior Member
    Computer Details
    numberOCD's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP EliteBook 8770w
    RAM:
    16Gb
    Using
    MEP 2014
    Join Date
    Apr 2010
    Location
    Chicago/New York USA
    Posts
    164

    Default

    Irm,
    Do I need spaces around the ^p? I haven't gotten it to work quite yet, but it is coming along.

    David,
    How would I use your this sequence? I'm not quite familiar with autolisp yet. I copied down the sequence and ran it through Script. Is this the proper method? I got a prompt: "Point or option keyword required." followed by "Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate]:"

  9. #9
    Forum Deity David Bethel's Avatar
    Discipline
    Multi-disciplinary
    David Bethel's Discipline Details
    Discipline
    Multi-disciplinary
    Details
    Commercial Food Service
    Using
    AutoCAD pre 2000
    Join Date
    Dec 2003
    Location
    Newport News, Virginia
    Posts
    2,534

    Default

    The simplest way would be to :


    Simply Copy Column "I" to the AutoCAD Command Line

    OR :
    • Copy column "I" into Notepad or any true ASCII editor
    • Save the new file to a known location ( c:\acad\insb.lsp] )
    • The file name and extension are not important in this scenario
    • At the AutoCAD command line type (load "c:/acad/insb.lsp")


    Notice the use of "/" vs the DOS standard for file locations. ( AutoLsip Requires this )

    Also the BLOCK / INSERT ATTRIBute quantities must be an exact match. In the same I posted MyBlock1 has (3) MyBlock2 has MyBlock3 has (2).

    There are work arounds for this but it didn't sound like that was a biggie for your use.
    Attached Files
    R12 (Dos) - A2K

  10. #10
    Senior Member
    Computer Details
    numberOCD's Computer Details
    Operating System:
    Windows 7
    Computer:
    HP EliteBook 8770w
    RAM:
    16Gb
    Using
    MEP 2014
    Join Date
    Apr 2010
    Location
    Chicago/New York USA
    Posts
    164

    Default

    Registered forum members do not see this ad.

    When I run the lsp named Test2.lsp it returns this test window
    Notice.jpg

    This is the only line in the lsp right now
    (command "_.INSERT" "SIG" list( 12 36 0) 1 1 32 "781Z" "GYR")

    Any idea what's wrong?

    Thanks

Similar Threads

  1. making a bom list from blocks with attributes
    By CADkitt in forum AutoLISP, Visual LISP & DCL
    Replies: 1
    Last Post: 13th Mar 2017, 08:21 am
  2. Rotate Dynamic Blocks on Insert with Option for Additional Rotate.
    By dortega4269 in forum AutoLISP, Visual LISP & DCL
    Replies: 26
    Last Post: 21st May 2013, 08:23 pm
  3. Insert blocks and rotate to polyline
    By woodman78 in forum AutoLISP, Visual LISP & DCL
    Replies: 2
    Last Post: 18th Apr 2013, 06:30 pm
  4. LISP to insert blocks depending on certain attributes
    By cangelo3D in forum AutoLISP, Visual LISP & DCL
    Replies: 6
    Last Post: 28th Oct 2009, 08:50 am
  5. update or insert blocks with attributes
    By serdas in forum AutoCAD General
    Replies: 24
    Last Post: 6th Nov 2008, 08:46 pm

Tags for this Thread

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