Jump to content

Inserting multiple blocks


Luís Augusto

Recommended Posts

Hello everybody.

In research here in the forum, I found a lisp program written by Lee Mac that makes the insertion of all the blocks in the drawing asking an insertion point. I found it very useful.

It would be possible to adapt to insert blocks reading from a csv file and bring the values ​​of attributes?

The blocks are not loaded in the drawing, so the directory is previously loaded in Suppot File Search Path.

 

This is the program mentioned above.

 

(DEFUN C:BLKINS  (/ pt name)
 (vl-load-com)
 
 (setq *acad* (vla-get-ActiveDocument
                (vlax-get-acad-object)))
 (setq *ms*   (vla-get-ModelSpace *acad*))

 (vlax-for item (vla-get-Blocks *acad*)

   (if (and (not (eq "*" (substr (setq name (vla-get-Name item)) 1 1)))
            (setq pt (getpoint "\nSelect Point for Block: ")))
     
     (vlax-invoke-method *ms* 'InsertBlock (vlax-3d-point pt) name 1.0 1.0 1.0 0.0)))

 (princ))

 

Thank you in advance.

 

Regards, Luís Augusto.

Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Luís Augusto

    13

  • Tharwat

    10

  • BIGAL

    1

  • Bhull1985

    1

Top Posters In This Topic

Posted Images

if you have a csv file then just open in excel and make a script you use the concatenate commnad in excel to join columns.

 

you need the line to be something like this

 

Insert block1 x,y 1 0 asdf ghjk.... two attributes

 

Insertblocksexcel.jpg

Link to comment
Share on other sites

if you have a csv file then just open in excel and make a script you use the concatenate commnad in excel to join columns.

 

you need the line to be something like this

 

Insert block1 x,y 1 0 asdf ghjk.... two attributes

 

Sorry Bigal . I think you misunderstood me .

I intend to find a routine that ask me the location of the table containing the values ​​of the blocks and their attributes , and then do the insertion of blocks asking me where the position will be inserted and not having to provide a coordinate x , y , z .

I found something like the following topic , but was unable to reuse code .

 

http://www.cadtutor.net/forum/showthread.php?53100-Inserting-blocks-and-attributes-with-LISP

 

I Requested the code for the holder but got no success, so I'm requesting help.

I Work with the design of electrical harnesses for agriculas machines and inserting attributes in connectors with loads of pinouts is quite laborious .

Today I use the excellent program Batch Attribute Editor Master Lee Mac , but still have to insert all connectors before making the importation of attributes . I would like to fully automate this task .

 

Does anyone know where to find something?

 

Thanks for help.

Link to comment
Share on other sites

As long as you have the drawing that contains the blocks in the Support folder , it would be easy to find and insert the drawing into the current one .

 

Upload a sample sheet of Excel fie with extension .csv

 

How would you insert the each block and how should the codes know that you are going with that block or another ?

Link to comment
Share on other sites

So from reading these posts I would guess that the OP wants to have tables in excel, electrical harnesses on one page, for instance.

So he tells the program which sheet number in excel document, and then the program grabs all of the cells and inserts based on the first column being the name of the block.

It would allow sequential insertion of the blocks with a click for each insertion point, where the program then places the block.

That's how I read it, HTH

Link to comment
Share on other sites

Tharwat, thank you for your interest in helping. :D

Following examples as requested.

Thank you in advance.

 

I wish I could :)

 

Now , how would you insert these blocks to drawings ? I mean the insertion point ?

Pick on the screen with pause option ?

Link to comment
Share on other sites

I wish I could :)

 

Now , how would you insert these blocks to drawings ? I mean the insertion point ?

Pick on the screen with pause option ?

 

The idea is the following. The program would let me know the name of the connector to be inserted and I choose the position manually.

Link to comment
Share on other sites

The tow blocks named Right headlight and Left headlight are having the last attributes with a strange one (value) to me , if you insert any value it keep on asking you for more inputs although in the Excel file there are only four values for the fore-said blocks .

 

So should the last attribute be with nil value to avoid the other asks for more values or what ?

Link to comment
Share on other sites

The tow blocks named Right headlight and Left headlight are having the last attributes with a strange one (value) to me , if you insert any value it keep on asking you for more inputs although in the Excel file there are only four values for the fore-said blocks .

 

So should the last attribute be with nil value to avoid the other asks for more values or what ?

 

Tharwat, sorry for the failure. TAG PN_ORIGINAL giving this problem. She is not more inside the block. You can ignore them.

The information should be entered only in tags that start with PIN_.

Man, I have no words to thank for their help and other colleagues here in the forum.

Thank you very much.

Link to comment
Share on other sites

So from reading these posts I would guess that the OP wants to have tables in excel, electrical harnesses on one page, for instance.

So he tells the program which sheet number in excel document, and then the program grabs all of the cells and inserts based on the first column being the name of the block.

It would allow sequential insertion of the blocks with a click for each insertion point, where the program then places the block.

That's how I read it, HTH

 

Dear bhull1985, forgive me for not seeing your comment. :oops:

Essentially this is the idea.

Many thanks for your interest in the subject and I'm sorry not to have answered before.

If you have any suggestion or idea to add, feel free.

 

Regards, Luis Augusto.

Link to comment
Share on other sites

Tharwat, sorry for the failure. TAG PN_ORIGINAL giving this problem. She is not more inside the block. You can ignore them.

The information should be entered only in tags that start with PIN_.

Man, I have no words to thank for their help and other colleagues here in the forum.

Thank you very much.

 

It's okay :)

 

I have just finished the routine and hope it would work as best as you looking for .

 

Try it and let me know .

 

(defun c:Test (/ *error* Deconstruct_String right left con1 con2 xl ok o st l lst a b c d f fp bn p go vl name ch)
 ;;                    ;;
 ;;    Author : Tharwat Al Shoufi    ;;
 ;;                    ;;
 (or doc (setq doc (vla-get-activedocument (vlax-get-acad-object))))
 (defun *error* (u)
   (if ch
     (setvar 'CMDECHO ch)
   )
   (princ "\n*Cancel*")
 )

 (defun Deconstruct_String (st delimiter / p l)
   (while (setq p (vl-string-search delimiter st 0))
     (setq l  (cons (substr st 1 p) l)
           st (substr st (+ p 2) (strlen st))
     )
   )
   (if st
     (setq l (cons st l))
   )
   (setq l (reverse l))
 )

 (if (setq xl (getfiled "Select the required Excel file :" (getvar 'DWGPREFIX) "csv" 16))
   (progn (setq ok t
                ch (getvar 'CMDECHO)
                o  (open xl "r")
          )
          (setvar 'CMDECHO 0)
          (while (setq st (read-line o))
            (setq l   (cons (setq st (Deconstruct_String st ",")) l)
                  lst (cons (strcase (car st)) lst)
            )
          )
          (close o)
   )
   (setq ok nil)
 )
 
 (if (and ok
          (/= (setq bn (getstring t "\n Specify Attributed Block name to insert :")) "")
          (if (member (setq bn (strcase bn)) lst)
            t
            (progn (alert "Block name is not included in the Excel file <!>") nil)
          )
          (if (not (tblsearch "BLOCK" bn))
            (if (setq fp (findfile (strcat bn ".dwg")))
              (progn (command "_.-insert" fp nil) t)
              (progn (alert "Block Name is not found in Support Folder <!>") nil)
            )
            t
          )
     )
   (progn (setvar 'CMDECHO ch)
     (vla-StartUndoMark doc)
          (while (setq p (getpoint "\n Specify insertion point :"))
            (setq vl (vla-insertblock (vla-get-block (vla-get-activelayout doc)) (vlax-3d-point p) bn 1.0 1.0 1.0 0.))
            (foreach x (vlax-invoke vl 'getattributes)
              (foreach tg l
                (if (and (eq (car tg) (strcase bn)) (eq (strcase (vla-get-tagstring x)) (cadr tg)))
                  (vla-put-textstring x (caddr tg))
                )
              )
            )
          )
     (vla-EndUndoMark doc)
   )
 )
 (princ)
)
(vl-load-com)

Edited by Tharwat
Codes Updated as per OP's needs
Link to comment
Share on other sites

It's okay :)

 

I have just finished the routine and hope it would work as best as you looking for .

 

Try it and let me know .

 

 

Tharwat, sorry for the delay in responding.

Did a great job my friend.

The program was very good, this is really the idea but, in my view two things would be interesting.

 

The first one would be to point the file location. Csv by explorer.

 

The second and more important in my opinion, would not limit the routine to certain connectors (names).

I believe the list to insert the blocks should be based on reading the first line of the file. Csv as quoted by BHULL1985. this way the program will become dynamic.

 

Thank you for your valuable contribution.

I believe this program can be used by many people.

 

Regards, Luís Augusto.

Link to comment
Share on other sites

Hi Luis .

 

Sorry for this late reply , a few urgent work prevented me to get back to you on time .

 

To allow the user to select the Excel file , that is easily could be done , but what about the blocks ?

 

How much is the quantity of blocks that you are planning to insert in each drawing and then to feed them with attribute values / strings ?

Link to comment
Share on other sites

Hi Luis .

 

Sorry for this late reply , a few urgent work prevented me to get back to you on time .

 

To allow the user to select the Excel file , that is easily could be done , but what about the blocks ?

 

How much is the quantity of blocks that you are planning to insert in each drawing and then to feed them with attribute values / strings ?

 

Do not worry Tharwat.

 

The path of the blocks will be informed before. I'll use the Support file search path, this way need not be handled by the program.

 

The amount of blocks, well, that can vary from 2 to 30, depending on the size of the project.

 

I imagined the following. The program will read the first column and generate a list of distinguished names for insertion. For each list item, then bring the values​​. This part of the program is already running fine.

Link to comment
Share on other sites

The path of the blocks will be informed before. I'll use the Support file search path, this way need not be handled by the program.

 

Does that mean that you have all needed blocks in the support folder ? and are listed in the Excel sheet as the one you uploaded before here ?

Link to comment
Share on other sites

Tharwat, the program is getting excellent!

Can I ask you one last change?

Could the program let me know the name of the conectors instead of a manual entry?

Edited by Luís Augusto
Link to comment
Share on other sites

What do you mean by that ? :danger:

 

Have I fixed your name.

Tharwat, I wrote wrong, sorry. :oops:

 

Here is a suggestion.

 

Prompt: Specify insertion point:

Then specific ...

Next

 

Prompt: Specify insertion point:

Then specific ...

Next

 

Until it runs out the possibilities ...

Edited by Luís Augusto
Link to comment
Share on other sites

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