Author Topic: Get Block  (Read 21390 times)

0 Members and 1 Guest are viewing this topic.

Joker

  • Guest
Get Block
« on: March 14, 2006, 12:07:28 PM »
I don’t know how to write a lisp.  But here is what I am looking to learn how to do.  I have an idea for a lisp the does the following.  Here is a description for your understanding: 

You have a block that is in a drawing and it does not exist in a Library.  With this lisp you would select the block and send it to a folder.  After you select the block that you want.  It maintains the name, the insertion point, colors, explodes the block, purges, sets it to layer 0 and sets it to 0,0.  If you need more information please feel free to ask.

nivuahc

  • Guest
Re: Get Block
« Reply #1 on: March 14, 2006, 12:15:03 PM »
I don’t know how to write a lisp.  But here is what I am looking to learn how to do.  I have an idea for a lisp the does the following.

and there was much rejoicing  :-)

Here is a description for your understanding: 

You have a block that is in a drawing and it does not exist in a Library.  With this lisp you would select the block and send it to a folder.  After you select the block that you want.  It maintains the name, the insertion point, colors, explodes the block, purges, sets it to layer 0 and sets it to 0,0.  If you need more information please feel free to ask.


I'm fairly certain that there are a number of existing routines that pretty much do what you are looking for (mostly)... but you said you wanted to learn.

Do you have a time frame for this? Is this something that you have an idea for and want to use it as a learning spring-board or are you under pressure to have it in order to accomplish some task/project?

Other than that, the only question that I can think of is: Where would you like to begin?

There are plenty of members here who will be happy to help you learn to whatever level you are willing. I'm afraid I could only cover the basics, and I'd probably confuse you more than anything. There are far more elegant teachers here than I.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Request for a Block Export Lisp
« Reply #2 on: March 14, 2006, 12:35:26 PM »
You probably already know this but wblock come close to doing what you want.

Quote
Command line  WBLOCK

To save a block or object as a separate drawing file

1   At the Command prompt, enter wblock.
2   In the Write Block dialog box, specify a block or an object to write out as a file.

Block: Specifies a block to save as a file.
   Entire Drawing: Selects current drawing as a block.
   Object: Specifies objects to be saved as a file.

3   Under Block, select a name from the list to save as a file.
4   Under Base Point, use the Pick Point button to define the base point.
5   Under Objects, use the Select objects button to select the object for the block file.
6   Enter a name for the new file.

If a block is selected, WBLOCK automatically uses that block's name for the new file.

7   In the Insert Units list, select an insert unit to use in AutoCAD DesignCenter.
8   Choose OK.

The block definition is saved as a drawing file.
« Last Edit: March 24, 2006, 11:47:34 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #3 on: March 14, 2006, 12:41:31 PM »
There is some great information to be found here as well. 
http://www.afralisp.co.za/
« Last Edit: March 14, 2006, 01:12:51 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Joker

  • Guest
Re: Get Block
« Reply #4 on: March 14, 2006, 12:46:15 PM »
You probably already know this but wblock come close to doing what you want.

Quote
Command line  WBLOCK

To save a block or object as a separate drawing file

1   At the Command prompt, enter wblock.
2   In the Write Block dialog box, specify a block or an object to write out as a file.

Block: Specifies a block to save as a file.
   Entire Drawing: Selects current drawing as a block.
   Object: Specifies objects to be saved as a file.

3   Under Block, select a name from the list to save as a file.
4   Under Base Point, use the Pick Point button to define the base point.
5   Under Objects, use the Select objects button to select the object for the block file.
6   Enter a name for the new file.

If a block is selected, WBLOCK automatically uses that block's name for the new file.

7   In the Insert Units list, select an insert unit to use in AutoCAD DesignCenter.
8   Choose OK.

The block definition is saved as a drawing file.

Yes, I know how to use the wblock coomand.

Joker

  • Guest
Re: Get Block
« Reply #5 on: March 14, 2006, 01:06:43 PM »
There is some great information to be found here as well. 
http://www.afralisp.co.za/

I cannot access this link.  It locks my cumputer up!
« Last Edit: March 14, 2006, 01:14:09 PM by CAB »

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #6 on: March 14, 2006, 01:10:06 PM »
Quote
Yes, I know how to use the wblock coomand.
Good, so you see it does what you want except for the changing of the layers.

Let me say this is not a trivial lisp & not one to make your first lesson with.

My first though is to modify the existing block to set the layers the way you want
and then wblock it to the new drawing file. This would leave the existing drawing with
modified block. That is entities on layer zero & fixed colors. Is that OK?
We are not considering nested blocks here.

My second thought is to Insert a new copy of the block, explode it, collect the new objects
change them to layer zero & color to match previous layer. The wblock them out & delete them.

Neither method is a simple thing to do.

Perhaps someone can come up with a simpler solution.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #7 on: March 14, 2006, 01:13:38 PM »
I cannot access this link.  It locks my cumputer up!

OK, change the link. Try again.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #8 on: March 14, 2006, 01:23:12 PM »
I don't think it should be that hard.  Insert the block (save the point, and set it to a variable using entlast).  Explode the block, step through all the entity with entnext, or if you use vla-Explode (it will put them all in a list).  Change all the entities to the way you want them.  And then wblock out the explode pieces, with the insertion point you saved.

Would this work?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

nivuahc

  • Guest
Re: Get Block
« Reply #9 on: March 14, 2006, 02:40:23 PM »
Actually, as daunting a task as this may seem to a beginner, there are some valuable core lessons that could be learned, one step at a time, if it's taught properly. Start simple, then make it complex.

For example: Lesson 1

Code: [Select]
(defun c: lesson_1 ()
  (ssget...
    (command...
    )
   )
  )
 
Then, once all of that is absorbed, move on to bigger and better things

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #10 on: March 14, 2006, 05:16:42 PM »
I don't think it should be that hard.  Insert the block (save the point, and set it to a variable using entlast).  Explode the block, step through all the entity with entnext, or if you use vla-Explode (it will put them all in a list).  Change all the entities to the way you want them.  And then wblock out the explode pieces, with the insertion point you saved.

Would this work?
Tim read this http://tinyurl.com/kqaez

Not that big a deal though, Jeff has a nice routine for collecting the exploded block.

Well how about some pseudo code?

I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #11 on: March 14, 2006, 05:26:57 PM »
My pseudo code.
Code: [Select]
User picks block to export
Insert the block at 0,0
Explode the block
Collect the new entities in a list
Change all the entities to color of layer if color ByLayer
Change all the entities to layer zero
wblock out the explode pieces, ? any user input ?
Delete the explode pieces

And this is the first lisp joker will write, so be through in your expiation. :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #12 on: March 14, 2006, 05:27:39 PM »
Tim read this http://tinyurl.com/kqaez

Not that big a deal though, Jeff has a nice routine for collecting the exploded block.

Well how about some pseudo code?



I have read that, and am disappointed in the fact that it doesn't work correctly.  Its a good read for others who don't know about that fault of vla-Explode.  Thanks for posting it here.

Code..... Maybe
Code: [Select]
(defun c:ReBlock ()
Select the block to be reblocked.
Insert said block, with scale values of 1 in all directions (save point, and name)
 note: with insertion block, and having scaling of all 1's, then you can use vla-Explode on it
Explode said block (one way or another, whatever you are comfortable with)
Step through each object, and change the properties, and add to a list (be careful about objects with subentities: blocks and old style polylines)
Wblock out all items in the list, with the name from before, and the insertion point
)

Or did you mean to write the actually code?
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Get Block
« Reply #13 on: March 14, 2006, 05:35:20 PM »
No you got it,  just pseudo code.

Here is a bit of code I got from somewhere.
It will take care of these two:
Quote
Explode the block
Collect the new entities in a list
Code: [Select]
(setq lst
   (mapcar
      'vlax-vla-object->ename
       (vlax-safeArray->list
          (vlax-variant-value
             (vla-Explode (vlax-ename->vla-object ename))
          )
       )
   )
)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

T.Willey

  • Needs a day job
  • Posts: 5251
Re: Get Block
« Reply #14 on: March 14, 2006, 05:46:21 PM »
No you got it,  just pseudo code.

Here is a bit of code I got from somewhere.
It will take care of these two:
Quote
Explode the block
Collect the new entities in a list
Code: [Select]
(setq lst
   (mapcar
      'vlax-vla-object->ename
       (vlax-safeArray->list
          (vlax-variant-value
             (vla-Explode (vlax-ename->vla-object ename))
          )
       )
   )
)

You could just do..
Code: [Select]
(setq EntList
 (mapcar
  'vlax-vla-object->ename
  (vlax-invoke (vlax-ename->vla-object Ent) 'Explode)
 )
)

Also remember that with vla-Explode, you leave the original object in place.
Tim

I don't want to ' end-up ', I want to ' become '. - Me

Please think about donating if this post helped you.