Jump to content

Inserting multiple blocks w/ a coordinates list.


Recommended Posts

Posted

It's telling me the four blocks have inserted, but I can't see them.

 

If the code works then it looks like I've incorrectly supplied the file location of my block.

 

I tell you what though, mate. If you could make the block selectable via the dialog menu in the same way the text file is selected that would enhance this routine immensely.

 

If you could also tell me how I need to correctly format the line where my block's file location goes that would be great, too.

 

(defun c:ITREE (/ *error* file1 blk pts)
   (defun *error* (msg)
   (setvar "cmdecho" 1)
   (if (= msg "")
       (princ (strcat (itoa blk) " Blocks Inserted."))
       (princ "\nError or Esc Pressed.")
   ) ;_  end if
   ) ;_  end defun
   (selfile)
   (setvar "cmdecho" 0)
   (setq file1    (open file "r")
     blk    0
   ) ;_  end setq
   (while
   (/= (setq pts (read-line file1)) nil)
      (command "-insert" "C:Documents and Settings\39925nt\My Documents\Nick's CAD\Blocks"
           pts    "" "" "0") ;_  end command
      (setq blk (1+ blk))
   ) ;_  end while
   (*error* "")
   (close file1)
   (princ)
) ;_  end defun
(defun selfile ()
   (setq file (getfiled "Select a Text File"
            "C:\\"
            "txt"
            9
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defunRemember to Insert the 

  • Replies 92
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    38

  • wannabe

    26

  • wizman

    8

  • ScribbleJ

    8

Posted

I can see my own problem. I didn't actually specify the full file location to the block itself.

Posted

Well my block is called North1. When I suffixed that onto the file location in the above code it said invalid block name.

Posted

When you specify a filepath, you will need to fomat it like the example below:

 

C:\\Users\\Lee Mac\\Documents\\Block1.dwg

 

Using the double backslashes and also specifying the filepath all the way down to the block name.

 

I'll have a work on it and see if I can work it with the dialog box :)

Posted

That should work for now:

 

(defun c:ITREE (/ *error* file1 blk pts)
   (defun *error* (msg)
   (setvar "cmdecho" 1)
   (if (= msg "")
       (princ (strcat (itoa blk) " Blocks Inserted."))
       (princ "\nError or Esc Pressed.")
   ) ;_  end if
   ) ;_  end defun
   (selfile)
   (setvar "cmdecho" 0)
   (setq file1    (open file "r")
     blk    0
   ) ;_  end setq
   (while
   (/= (setq pts (read-line file1)) nil)
      (command "-insert" "C:\\Documents and Settings\\39925nt\\My Documents\\Nick's CAD\\Blocks\\North1.dwg"
           pts    "" "" "0") ;_  end command
      (setq blk (1+ blk))
   ) ;_  end while
   (*error* "")
   (close file1)
   (princ)
) ;_  end defun

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

Posted

Excellent job, mate.

 

Have yourself a mince pie and a pork sandwich (only when the block is selectable via dialog box, mind :D ).

 

No, that's great as it is.

 

Maybe I can return the favour when I'm upto speed with .NET.

Posted

Ok, try this:

 

(defun c:ITREE (/ *error* file1 blk blkfile pts)
   (defun *error* (msg)
   (setvar "cmdecho" 1)
   (if (= msg "")
       (princ (strcat (itoa blk) " Blocks Inserted."))
       (princ "\nError or Esc Pressed.")
   ) ;_  end if
   ) ;_  end defun
   (selfile)
   (blocksel)
   (setvar "cmdecho" 0)
   (setq file1    (open file "r")
     blk    0
   ) ;_  end setq
   (while
   (/= (setq pts (read-line file1)) nil)
      (command "-insert" blkfile pts "1" "1" "0") ;_  end command
      (setq blk (1+ blk))
   ) ;_  end while
   (*error* "")
   (close file1)
   (princ)
) ;_  end defun

(defun selfile ()
   (setq file (getfiled "Select a Text File"
            "C:\\Documents and Settings\\39925nt\\My Documents\\Nick's CAD"
            "txt"
            8
          ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

(defun blocksel    ()
   (setq blkfile (getfiled "Select a Block"
               "C:\\Documents and Settings\\39925nt\\My Documents\\Nick's CAD\\Blocks"
               "dwg"
               8
         ) ;_  end getfiled
   ) ;_  end setq
) ;_  end defun

Posted

Nice work again.

 

I hope Santa gives you a nice new Ferrari.

Posted
Nice work again.

 

I hope Santa gives you a nice new Ferrari.

 

Haha that'll be the day :P

 

Merry Christmas to you too :)

Posted

Ok Lee I had some time to give this Lisp a test run. I ran the very last one shown and here is the results.

 

Block Tree references itself

*Invalid*

 

Just wanted to give you an update. I am going to try to figure out the problem myself but if you do squash this bug I would be very interested to see the solution. I'm really getting a handle on Lisp now. I'm starting to feel somewhat smarter now.

 

:roll: o:) :lol:

 

What I don't understand is why it references itself. It is not in the dwg file. I'm starting it from scratch.

Posted

Hi Scribs

 

does the tree block have any attributes?

 

Cheers

 

Lee

 

EDIT:

 

Only reason I put this point forward is that Wannabe could make the LISP function correctly with his blocks, therefore it leads me to think that there is something inherent in your block to cause the error - usually another block combined with itself to form the final block - or a dodgy attribute.

Posted

Final Update:

 

(Updated the Error Handler)

 

(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
   (/= (setq pts (read-line file1)) nil)
      (command "-insert" blkfile pts "1" "1" "0")
      (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
Hi Scribs

 

does the tree block have any attributes?

 

Cheers

 

Lee

 

EDIT:

 

Only reason I put this point forward is that Wannabe could make the LISP function correctly with his blocks, therefore it leads me to think that there is something inherent in your block to cause the error - usually another block combined with itself to form the final block - or a dodgy attribute.

 

I will check this out. I thought I had a vanilla tasting block but I'm not 100% certain.

 

Time: 20:10

Just checked (15 minutes after the original post). It is a plain 'ole vanilla tasting block. I'm running some more test at the time of this posting. Gotta love VPN.

 

Time: 20:36

Ok I did another test run and it worked perfectly. Thank you billionz of times over.

 

EUREKA!

Posted

Lee Mac, or anyone else, what do you think about this?:

 

Is there any way that we can add one more function to this routine?

 

Basically I am delighted that I can specify a block, point to an excel list of coordinates and then my job is done.... But, my job isn't exactly done.

 

What would be amazing, is, if the lisp would also look at the coordinate list and notice that before the actual coordinates is a text string that represents the identification number for that block.

 

If the identification could then populate an attribute in my block called I.D, that would be immense and save me a lot of time.

 

Not a problem if it can't be done. But a big help if it can.

 

Cheers.

Posted

I suppose it would be easier if you had the attribute on either the line above or below the coordinates - then you could just perform the read-line alternately and read coordinate then attribute and so on so on..

Posted

If it was indeed the case that the attribute was on a new line, and was prompted for when the block was inserted, this may work :)

 

(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)
       (/= (setq atrib (read-line file1)) nil)
   ) ;_  end or
      (command "-insert" blkfile pts "1" "1" "0" atrib)
      (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

 

Only a quick work-around - haven't thought about this one much.

Posted

A few bites to eat and I'll let you know.

 

Either way, thanks for taking the time, Lee.

Posted

It came up with a function cancelled error message and then acted in the normal block insertion manner (via the command line).

 

Attached are the text file and one of the blocks I would be using with the previously mentioned I.D attributes, incase this helps anyone to solve the problems.

samppy.txt

Proposed Borehole - Red10.dwg

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...