Jump to content

Inseret a group of blocks in array with a defined series


Recommended Posts

Posted

In my file I have some pre-defined blocks let us name it as "A", "B" and "C".

 

The problem is how to insert these blocks in array with a defined series such as " A, A, B, C, C, C, A" or any other series in one step.

 

I do not know Vlisp but in general I think that we can follow the following setps:

1- the program will ask the user to Insert the series (simply the series is already written in a txt file so we can copy the series from the txt file and past it in the command line.)

2- Ask for the insertion point.

3- Ask wethere to insert it as row or column.

4- specify the spacing between blocks.

 

Is there any one who has a lips to do this task.

 

Thnx

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • asos2000

    7

  • pBe

    7

  • Fathy81

    4

  • BIGAL

    3

Top Posters In This Topic

Posted (edited)

quick one

 

(defun _insert  (p bn ang ds)
     (vlax-invoke
           (vlax-get
                 (vla-get-ActiveLayout
                       (vla-get-activedocument
                             (vlax-get-acad-object)))
                 'Block)
           'InsertBlock
           p
           bn
           1
           1
           1
           0)
     (polar p ang ds)
     )
(defun c:test  ()
     (setq blk '("A" "B" "B" "C" "A" "B" "C")
           pt  (getpoint "\nPick Insertion point:"))
     (if (not dist)
           (setq dist 1.00))
     (setq dist (cond
                      ((getdist
                             (strcat "\nEnter Distance <"
                                     (rtos dist 2 2)
                                     ">: ")))
                      (dist)))
     (if (not angl)
           (setq angl 0.00))
     (setq angl (cond
                      ((getangle
                             (strcat "\nEnter Angle <"
                                     (angtos angl 0)
                                     ">: ")))
                      (angl)))
     (foreach
            bn
              blk
           (setq pt (_insert pt bn angl dist)))
     )

     

 

HTH

GTG

Edited by pBe
add prompt...
Posted

The lisp seems good but actually it didn't work with me.

 

also it did not ask me to enter the series of the block names. the series is variable that vary from file to another so it should be a variable and the user has to insert it each time as a string separated with comma

Posted (edited)

The line (setq blk '("A" "B" "B" "C" "A" "B" "C") needs to be replaced by a read a line from a txt file the code was supplied as an example of how to commence towards an answer to your question.

 

This might be a good time to start learning lisp theres plenty here who will help.

 

As a help had a go at (getstring) and pasting "A" "B" "B" "C" "A" "B" "C" once it hits the spaces it stops which is normal any ideas guys, there must be a way of using the paste function as a variable. I know I could trick it by using dummy text where the paste is acceptable.

Edited by BIGAL
Posted
The lisp seems good but actually it didn't work with me.

 

1. Have no idea the what your text file looks like.

2. Its starting point for you (hence c:test)

 

This might be a good time to start learning lisp theres plenty her who will help.

 

Yup :thumbsup:

 

As a help had a go at (getstring) and pasting "A" "B" "B" "C" "A" "B" "C" once it hits the spaces it stops which is normal any ideas guys, there must be a way of using the paste function as a variable. I know I could trick it by using dummy text where the paste is acceptable.

 

Yes, it can be done that way, accept the comma delimited string then parse. parsing is not really necessary depending on the format the OP has it on the text file to which i'm totally clueless, could very well be "A" "B" "B" "C" "A" "B" "C" or a sub to read a text file. either way, its up to the OP

 

Flag T will allow space " "

 

(setq blk (getstring [b][color=blue]T[/color][/b] "\nPaste Block Names: "))
(setq blk (read (strcat "("  blk  ")")))

 

Paste Block Names: "A" "B" "B" "C" "A" "B" "C"

("A" "B" "B" "C" "A" "B" "C")

 

or if by chance the text file is this format A B B C A B C (no comma, not quotations)

 

 

(setq blk (getstring T "\nPaste Block Names: "))
(setq blk (mapcar 'vl-symbol-name (read (strcat "("  blk  ")"))))

 

Paste Block Names: A B B C A B C

("A" "B" "B" "C" "A" "B" "C")

 

Cheers

Posted
Thanks Pbe for the T may come in handy one day.

 

Cheers Bigal :beer:

Posted

Fathy81 its your turn now. Its nice to let others know you got the answer you were after.

Posted

First of all I would like to thank u all for ur help. The lisp worked very well with me specially when we used the "T" flage so it met the format of the spaces delmited txt file (i.e. A A A B B B C ... ) . The comma delmited file will be much better.

 

Actually the formate of the txt file is the same as the formate of txt file that AutoCAD export it by the command (Expresses - export attribute information).Here under is a sample for the formate of the txt file:

 

HANDLE BLOCKNAME

'42C50 U14

'391FA U270

'391BA U271

 

The names of the blocks are arranged in the 2nd column (i.e. U14, U270 and U271). but the issue here is the "enter" between rows.

 

To overcome this issue I opened the txt file in xls then I copied the 2nd column and use the command "past special - transpose" to transpose the column to become row. then I save it again in the same txt formate then I open it as txt file as comma delmitted then replace commas with spaces to meet the format of the txt file familiar to CAD (spaces delmitted). then I past it. These are the steps that I follow.

 

 

 

 

 

 

 

 

1. Have no idea the what your text file looks like.

2. Its starting point for you (hence c:test)

 

 

 

Yup :thumbsup:

 

 

 

Yes, it can be done that way, accept the comma delimited string then parse. parsing is not really necessary depending on the format the OP has it on the text file to which i'm totally clueless, could very well be "A" "B" "B" "C" "A" "B" "C" or a sub to read a text file. either way, its up to the OP

 

Flag T will allow space " "

 

(setq blk (getstring [b][color=blue]T[/color][/b] "\nPaste Block Names: "))
(setq blk (read (strcat "("  blk  ")")))

 

Paste Block Names: "A" "B" "B" "C" "A" "B" "C"

("A" "B" "B" "C" "A" "B" "C")

 

or if by chance the text file is this format A B B C A B C (no comma, not quotations)

 

 

(setq blk (getstring T "\nPaste Block Names: "))
(setq blk (mapcar 'vl-symbol-name (read (strcat "("  blk  ")"))))

 

Paste Block Names: A B B C A B C

("A" "B" "B" "C" "A" "B" "C")

 

Cheers

Posted

To overcome this issue I opened the txt file in xls then I copied the 2nd column and use the command "past special - transpose" to transpose the column to become row. then I save it again in the same txt formate then I open it as txt file as comma delmitted then replace commas with spaces to meet the format of the txt file familiar to CAD (spaces delmitted). then I past it. These are the steps that I follow.

 

You ca do without transposing and converting the file for Autocad to recognize the format (Autocad is not limited to space delimited format), if we have known the file format you are using on the get-gp, we could've save you time from converting the file. reading the block names from a external source would've been cleaner.

 

But at any rate., it works for you as it is. and its better than not at all ;)

 

Cheers

Posted
You ca do without transposing and converting the file for Autocad to recognize the format (Autocad is not limited to space delimited format), if we have known the file format you are using on the get-gp, we could've save you time from converting the file. reading the block names from a external source would've been cleaner.

 

But at any rate., it works for you as it is. and its better than not at all ;)

 

Cheers

 

 

That's correct. Your lisp gave me a great advance. Thanks alot.icon7.gif

  • 2 weeks later...
Posted

im resurrecting this thread as i need the same lisp, but i cant make it work for my blocks. any idea how to go around this??? i dont know much abt lisp thanks

 

i want to paste 3 types of blocks (A, B, ,C,)

Posted (edited)
im resurrecting this thread as i need the same lisp, but i cant make it work for my blocks. any idea how to go around this??? i dont know much abt lisp thanks

 

i want to paste 3 types of blocks (A, B, ,C,)

 

(defun _insert  (p bn ang ds)
; Author pBe 
; http://www.cadtutor.net/forum/showthread.php?66836-Inseret-a-group-of-blocks-in-array-with-a-defined-series&p=457386&viewfull=1#post457386

     (vlax-invoke
           (vlax-get
                 (vla-get-ActiveLayout
                       (vla-get-activedocument
                             (vlax-get-acad-object)))
                 'Block)
           'InsertBlock
           p
           bn
           1
           1
           1
           0)
     (polar p ang ds)
     )
(defun c:test  ()
; Author pBe 
; http://www.cadtutor.net/forum/showthread.php?66836-Inseret-a-group-of-blocks-in-array-with-a-defined-series&p=457386&viewfull=1#post457386

 (setq blk (getstring T "\nPaste Block Names: "))
 (setq blk (mapcar 'vl-symbol-name (read (strcat "("  blk  ")"))))
 (setq pt  (getpoint "\nPick Insertion point:"))
 
     (if (not dist)
           (setq dist 1.00))
     (setq dist (cond
                      ((getdist
                             (strcat "\nEnter Distance <"
                                     (rtos dist 2 2)
                                     ">: ")))
                      (dist)))
     (if (not angl)
           (setq angl 0.00))
     (setq angl (cond
	   ((getangle
	      (strcat "\nEnter Angle <"
		      (angtos angl 0)
		      ">: ")))
	   (angl)))
     (foreach
            bn
              blk
           (setq pt (_insert pt bn angl dist)))
     )

 

Paste Block Names: A B B C A B C

Edited by asos2000
Author name added
Posted
(defun _insert  (p bn ang ds)
     (vlax-invoke
           (vlax-get
                 (vla-get-ActiveLayout
                       (vla-get-activedocument
                             (vlax-get-acad-object)))
                 'Block)
           'InsertBlock
           p
           bn
           1
           1
           1
           0)
     (polar p ang ds)
     )
(defun c:test  ()
 (setq blk (getstring T "\nPaste Block Names: "))
 (setq blk (mapcar 'vl-symbol-name (read (strcat "("  blk  ")"))))
 (setq pt  (getpoint "\nPick Insertion point:"))
 
     (if (not dist)
           (setq dist 1.00))
     (setq dist (cond
                      ((getdist
                             (strcat "\nEnter Distance <"
                                     (rtos dist 2 2)
                                     ">: ")))
                      (dist)))
     (if (not angl)
           (setq angl 0.00))
     (setq angl (cond
	   ((getangle
	      (strcat "\nEnter Angle <"
		      (angtos angl 0)
		      ">: ")))
	   (angl)))
     (foreach
            bn
              blk
           (setq pt (_insert pt bn angl dist)))
     )

 

Paste Block Names: A B B C A B C

 

What's if the block name is written wrongly by a user or the block is not existed in current drawing ?

Posted
What's if the block name is written wrongly by a user or the block is not existed in current drawing ?

 

Thnaks for your reply so we waiting for your solution.

Second Please read this and this too Mr pBe He who wrote the lisp not me

 

Thanks again for your reply

Posted

read this and this too Mr pBe He who wrote the lisp not me

 

 

since so , you should keep or add the author name of the routine or at least post the link that related to codes as you did in your post No# 15

 

 

we waiting for your solution.

 

There won't be any solution by me since that code is not belong to you , and will never step over pBe 's toes for any kind of reasons .

Posted (edited)
since so , you should keep or add the author name of the routine or at least post the link that related to codes as you did in your post No# 15

.

I did not add my my name as the author. And did not copy the code to another thread. I am replying in the same thread

Any way I edited the post to add pBe name

 

There won't be any solution by me since that code is not belong to you , and will never step over pBe 's toes for any kind of reasons .

Again I did not add my name as the author. pBe is 100% the owner of this lisp and the modifications. I just collect from here and there

 

To moderators was I make mistakes and/or showing at any where that I am the author of the lisp?

Edited by asos2000
Posted

To moderators was I make mistakes and/or showing at any where that I am the author of the lisp?

 

The author did not put his name on the routine and it is not your responsibility to do that for him, but if you do know the author's name, it is common courtesy to mention it in your post, just to give credit and make it clear that the code you are posting is not yours. ;)

 

BTW: If you guys want to get recognized for the code you write, you should put your name in the header. :thumbsup:

Posted
The author did not put his name on the routine and it is not your responsibility to do that for him.......

 

True :)

 

BTW: If you guys want to get recognized for the code you write, you should put your name in the header. :thumbsup:

 

Its not about that really, as long as the code i write helps the OP (on my own little way) , then its good enough for me ;)

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