Jump to content

Inserting multiple blocks w/ a coordinates list.


Recommended Posts

Posted

There is a chance the error may be related to the format of the .txt file I tried to use. I'll update when confirmed.

  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    38

  • wannabe

    26

  • wizman

    8

  • ScribbleJ

    8

Posted

Definitely a problem with the .txt file. I have tried everything, but only on list of coordinates works. Ive even tried to replicate the structure of that file but to no avail.

Posted

Ok, I have some good news.

 

Basically, to make the coordinates text file readable to the lisp they need to be saved as an rtf in word and then saved as a plain text .txt file format, with a comma separating the coordinates.

 

As for the automatic identification entry, it just asks me to manually type in the information to populate this attribute for the block. Which is a slight problem in the fact I don't know which order they are inserted.

 

Any help appreciated.

Posted

Basically, to make the coordinates text file readable to the lisp they need to be saved as an rtf in word and then saved as a plain text .txt file format, with a comma separating the coordinates.

 

A little hint to make things more simple, would be to open your coordinate file in Excel, then you can save as a CSV file format, and commas are inserted automatically between the coordinates and the file is in a format that can be read in Lisp. :)

Posted

The way my posted LISP works is that it reads alternate coords and attributes., then assuming the attribute is prompted for, it will submit the attirbute value.

(defun c:ITREE (/ *error* file file1 blk blkfile pts)
   (defun *error* (msg)
   (setvar "cmdecho" 1)
   (if (= msg "")
       (princ (strcat (itoa blk) " Blocks Inserted."))
       (princ (strcat "\n" (strcase msg)))
   ) ;_  end if
   ) ;_  end defun
   (selfile)
   (blocksel)
   (setvar "cmdecho" 0)
   (setq file1    (open file "r")
     blk    0
   ) ;_  end setq
   (while
   (or
       (/= (setq pts (read-line file1)) nil) ; [color=Red]READING COORDINATE[/color]
       (/= (setq atrib (read-line file1)) nil) ; [color=Red]READING ATTRIBUTE[/color]
   ) ;_  end or
      (command "-insert" blkfile pts "1" "1" "0" atrib) ; [color=Red]PASTING ATTRIBUTE TO COMMAND LINE[/color]
      (setq blk (1+ blk))
   ) ;_  end while
   (*error* "")
   (close file1)
   (princ)
) ;_  end defun

(defun selfile ()
   (setq file (getfiled "Select a Text File"
            "C:\\"
            "txt"
            8
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

(defun blocksel    ()
   (setq
   blkfile    (getfiled "Select a Block"
             "C:\\"
             "dwg"
             8
       ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

Posted

What is it that is not working?

 

Is it not getting to the coordinated point, or is it not inserting the block with the correct attribute, or what? :cry:

Posted

I'm assuming its something to do with the attribute, seeing as you could get the block inserted without the addition of the attribute codeing.

Posted

When I tried to insert the block, it needed the attribute, then it needed the attribute to be verified. So the attribute must be entered twice :( or the attribute should be edited so that it doesn't need verification.

Posted
I'm assuming its something to do with the attribute, seeing as you could get the block inserted without the addition of the attribute codeing.

 

 

what is the value of your attreq?

One note for inserting blocks with attributes in a lisp routine, you must ensure your attreq system variable is set to 1

Posted

Excellent point Wizman, I did not know of that variable - thanks for pointing that out.

Posted

Here is an updated LISP, including setting the attreq to 1:

 

(defun c:ITREE (/ *error* file file1 blk blkfile pts atrib)

   (defun *error* (msg)
   (mapcar 'setvar varlist oldvars)
   (if (= msg "")
       (princ (strcat (itoa blk) " Blocks Inserted."))
       (princ (strcat "\n" (strcase msg)))
   ) ;_  end if
   ) ;_  end defun

   (setq varlist (list "CMDECHO" "ATTREQ")
     oldvars (mapcar 'getvar varlist)
   ) ;_  end setq

   (selfile)
   (blocksel)
   (setvar "CMDECHO" 0)
   (setvar "ATTREQ" 1)
   (setq file1    (open file "r")
     blk    0
   ) ;_  end setq
   (while
   (or
       (/= (setq pts (read-line file1)) nil) ; READING COORDINATE
       (/= (setq atrib (read-line file1)) nil) ; READING ATTRIBUTE
   ) ;_  end or
      (command "-insert" blkfile pts "1" "1" "0" atrib) ; PASTING ATTRIBUTE TO COMMAND LINE
      (setq blk (1+ blk))
   ) ;_  end while
   (*error* "")
   (close file1)
   (princ)
) ;_  end defun

(defun selfile ()
   (setq file (getfiled "Select a Text File"
            "C:\\"
            "txt"
            8
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

(defun blocksel    ()
   (setq
   blkfile    (getfiled "Select a Block"
             "C:\\"
             "dwg"
             8
       ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

Posted

Have you tried to insert wannabe's block manually? It needs an extra return at the end, because the attribute needs verification.

Posted

Thanks for the comments and effort. Learnt a few new things and got myself a really handy LISP.

 

I can chat up the receptionist all day when I should be manually inserting blocks and changing the attributes.

 

:D

 

P.S I better check it at work before I get too carried away.

Posted
I can chat up the receptionist all day when I should be manually inserting blocks and changing the attributes.

 

LISP is good for something then... :P :D

Posted

I see what you mean Eldon, Wannabe's Block has a double prompt for attribs - may need to double the LISP input:

 

(defun c:ITREE (/ *error* file file1 blk blkfile pts atrib)

   (defun *error* (msg)
   (mapcar 'setvar varlist oldvars)
   (if (= msg "")
       (princ (strcat (itoa blk) " Blocks Inserted."))
       (princ (strcat "\n" (strcase msg)))
   ) ;_  end if
   ) ;_  end defun

   (setq varlist (list "CMDECHO" "ATTREQ")
     oldvars (mapcar 'getvar varlist)
   ) ;_  end setq

   (selfile)
   (blocksel)
   (setvar "CMDECHO" 0)
   (setvar "ATTREQ" 1)
   (setq file1    (open file "r")
     blk    0
   ) ;_  end setq
   (while
   (or
       (/= (setq pts (read-line file1)) nil) ; READING COORDINATE
       (/= (setq atrib (read-line file1)) nil) ; READING ATTRIBUTE
   ) ;_  end or
      (command "-insert" blkfile pts "1" "1" "0" atrib atrib) ; PASTING ATTRIBUTE TO COMMAND LINE
      (setq blk (1+ blk))
   ) ;_  end while
   (*error* "")
   (close file1)
   (princ)
) ;_  end defun

(defun selfile ()
   (setq file (getfiled "Select a Text File"
            "C:\\"
            "txt"
            8
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

(defun blocksel    ()
   (setq
   blkfile    (getfiled "Select a Block"
             "C:\\"
             "dwg"
             8
       ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

Posted

please try.....:-):

(defun c:ITREE (/ *error* file1 blk blkfile pts atrib file_link)
   (defun *error* (msg)
(mapcar 'setvar varlist oldvars)
(princ (strcat "\n" (strcase msg)))
   ) ;_  end defun

   (setq varlist (list "ATTREQ" "CMDECHO" "OSMODE")
  oldvars (mapcar 'getvar varlist)
   ) ;_  end setq
   (selfile)
   (blocksel)
   (setvar "CMDECHO" 0)
   (setvar "ATTREQ" 1)
   (setvar "OSMODE" 0)
   (setq file1	(open file "r")
  blk	0
   ) ;_  end setq
   (while
(and
    (setq file_link (read-line file1))
    (setq atrib	(vl-princ-to-string
		    (car (read (strcat "(" file_link ")")))
		) ;_ end_VL-PRINC-TO-STRING
    ) ;_ end_setq
    (setq pts (read (strcat "(" (read-line file1) ")")))
) ;_  end or
   (command "-insert" blkfile pts "1" "1" "0" atrib ATRIB)
   (setq blk (1+ blk))
   ) ;_  end while
   (princ (strcat (itoa blk) " Blocks Inserted."))
   (close file1)
   (*error* "")
   (princ)
) ;_  end defun

(defun selfile ()
   (setq file (getfiled "Select a Text File"
		 "C:\\"
		 "txt"
		 8
       ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

(defun blocksel	()
   (setq
blkfile	(getfiled "Select a Block"
		  "C:\\"
		  "dwg"
		  8
	) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

Posted

The last routine gives the error: "NO FUNCTION DEFINITION: BLOCKSEL" as soon as the text file is selected.

 

EDIT: The last routine from Lee.

Posted

What format will the text file need to be in Wizzman? I.e, where will I need to place the text that will be used to populate the attribute?

 

By default it comes out as attribute,coordx,coordy.

Posted

same as posted samppy.txt, i had a quick ran at it, too tight sched right now, try to come back later

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...