Explode block, change layer and re-block

Explode block, change layer and re-block

m_rogoff
Advocate Advocate
3,149 Views
16 Replies
Message 1 of 17

Explode block, change layer and re-block

m_rogoff
Advocate
Advocate

I would love this in macro form, but realize it may be too advanced and require lisp.

 

I have a block with a polyline and hatch (in the shape of a wide flange beam). I want to select the block; explode; delete the hatch; change layer to S-COL; re-block as the same name as the original block; redefine the block; and use the center point of the geometery as base point. 

 

If this is in macro form, what would I need to sacrifice to make this work?

Thanks for your help in advance

0 Likes
3,150 Views
16 Replies
Replies (16)
Message 2 of 17

Kent1Cooper
Consultant
Consultant

Are there multiple insertions of this Block already in the drawing?  If so, there are routines around [for instance, this] that are built to change the insertion point of a Block's definition and re-position all existing insertions of it so their contents don't move in the process.  I doubt that can be accomplished by a macro.  But if you only have the one insertion to make these changes in, a macro could well do it, with a little AutoLisp included in it to find the Hatch and Erase it, and to find the wide-flange outline [may I assume it's a Polyline?] to change its Layer, without your needing to select either, and to find the middle of the outline so as to re-position it around the base point.  Apart from the base point issue, I think a macro could do it without AutoLisp if you don't mind selecting those pieces and can count on selecting the right one for each step and not missing.  But I expect it would be better [even easier] to make an AutoLisp routine, and have that invoked by the menu item in which you would have put the macro.

Kent Cooper, AIA
Message 3 of 17

scot-65
Advisor
Advisor
^C^C-insert;BLOCK-NAME=;Y;0,0;1;;;erase;Last;;
Where "Block-Name" is a block located in your support path that has been updated to the parameters you desire.

As far as changing layer, you did not say to change the parent or the children of the parent to the desired layer?

You desire to keep the original block with the hatch?
If so, declare a support path to a newly created folder and place this path above your symbol library directory path; which will allow the newer definition to be read first.

Placing the hatch on a separate layer to the pline nets the use of the layer's On/Off or Freeze/Thaw functionality. Just employ the method you do not normally use.

Judging by your ranking, you have already considered this?

[UNTESTED, Kent]

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

Message 4 of 17

m_rogoff
Advocate
Advocate

Hi, thanks for your input. I need to clarify and answer a few questions.

My library is full of steel Wide Flange sizes. They are made for cross sections. I want to pick a size to insert into Plan (either typing the block name or selecting it from the Tool Palette). The layer and pick point need to change for the Plan drawing. This itteration of the block will only reside in the drawing and the library will remain unchanged.

 

1. Assume this will be the first block instance in the drawing, so no need to re-position. No need to save the modified version of the block, it will only be modified in certain drawings.

2. Outline of WF is one polyline

3. The layer to change is linework inside of the block 

4. Half the office is on LT, so macro is prefered 

5. I do not mind manually selecting the object

6. The hatch is on a layer that is common in the job, so I can't just turn off the layer. However, I could run a batch routine (I already have one written) to change the layer name in each block so it is unique to the steel hatch, making it easy to freeze in plan.

 

 

Hope this helps, thanks

 

 

0 Likes
Message 5 of 17

scot-65
Advisor
Advisor
I hear you on the LT issue.
Looks like #6 would be the way to go.
This would involve iterating thru your library and directing the hatch to the appropriate layer. I think there is something in this forum that can do this in batch mode however, I'm not sure. Whoops, you mentioned this...

One other item I can think of is the color of the hatch.
Is it a unique color? Meaning is it a color only used for this hatch?
Thinking in lines of a CTB setup, create two pen tables, one is the default and the other has this color assigned as a grayscale, and to have the grayscale value set to 0% - Meaning it will not print.

Just a thought.

???

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 6 of 17

m_rogoff
Advocate
Advocate

This is where I am at right now:

 

I was thinking about using RefEdit to edit the last block inserted. I do not know how to get it to select "Last" or "Previous".

(type in block name)

^C^C-insert;\\;;;_refedit;

 

This to delete the hatch layer, which was recently changed to a unique layer name (thanks Scot)

-laydel;n;S-HATCH;;y;

 

This to change the layers.

chprop;all;;Layer;S-COL;;

 

Is it possible to add a  BParameter Alignment = Perpendicular, or change the basepoint to center of line geometery while in Refedit?

 

Does it complicate the alignment parameter is the block was inserted at a rotated angle?

 

Thanks

0 Likes
Message 7 of 17

hmsilva
Mentor
Mentor

@m_rogoff wrote:

This is where I am at right now:

 

I was thinking about using RefEdit to edit the last block inserted. I do not know how to get it to select "Last" or "Previous".

(type in block name)

^C^C-insert;\\;;;_refedit;

 ...


Hi m_rogoff,

 

to the 'refedit' part, try

 

^C^C-insert;\\;;;_.-refedit;$M=$(getvar,lastpoint);

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 8 of 17

hmsilva
Mentor
Mentor

Hi m_rogoff,

probably I would use the '-bedit' command to edit the block.


The hatch and layer change, I didn't included because you have already solved.

 

I did try to put together a 'macro' to do this task, unsuccessfully...

^C^C-insert;\\;;;_.-bedit;$M=$(getvar,insname);

 will open the block editor with the last inserted block,

_move;_all;;$M=$(getvar,viewctr);0,0;_.bparameter;_A;0,0;;_Perpendicular;0,1;_BSAVE;_BCLOSE;

 will put the insertion point in the center of the geometry, add a perpendicular bparameter and save, close BEditor, but...

^C^C-insert;\\;;;_.-bedit;$M=$(getvar,insname);_move;_all;;$M$(getvar,viewctr);0,0;_.bparameter;_A;0,0;;_Perpendicular;0,1;_BSAVE;_BCLOSE;

 

will not work as expected, the viewctr will be the model space viewctr, not the block editor viewctr...

 

Probably I'm missing something...

 

Henrique

EESignature

0 Likes
Message 9 of 17

m_rogoff
Advocate
Advocate

Henrique, thanks this is very close. You are right, it is not grabbing the center geometery point. On second thought, I'd like to keep the original basepoint, but add the alignment at geometery center if possible. I re-arragned the code a bit, but it's not Getvar the Viewctr.

I like the Bedit approach but I am curious if there is a way to supress the dialogue box upon exiting Beidtor. (filedia=0 does not work).

 

As an alternative, it may be better to add an alignment parameter to the block master copy. I posted here (link below) for adding the alignment parameter which I would run with my batch script to change the hatch layer. Very similar to this 

 

 

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/bparameter-alignment/td-p/5602078

 

 

 

^C^C-insert;\\;;;_.-bedit;$M=$(getvar,insname);_.bparameter;_A;$M$(getvar,viewctr);_Perpendicular;0,1;_BSAVE;_BCLOSE;

0 Likes
Message 10 of 17

m_rogoff
Advocate
Advocate

_dview;all;;points;

 

this gives me a target point in XYZ coordinants. I need to specify this as the base point of alignment

 

Specify target point <0'-0", -0'-3", 0'-0">

 

viewctr command returns <read only> . If you zoom all first, viewctr will be center of object as well

 

oops, BSAVE supresses the B/Editor dialogue box

0 Likes
Message 11 of 17

hmsilva
Mentor
Mentor

@m_rogoff wrote:

_dview;all;;points;

 

this gives me a target point in XYZ coordinants. I need to specify this as the base point of alignment

 

Specify target point <0'-0", -0'-3", 0'-0">

 

viewctr command returns <read only> . If you zoom all first, viewctr will be center of object as well

 

oops, BSAVE supresses the B/Editor dialogue box


_dview;all;;points;;;;

will exits dview command, and

$M=$(getvar,target);

will get the target value to the command line.

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 12 of 17

m_rogoff
Advocate
Advocate

I have two variations, neither one is getting variable. I changed it up a bit, got rid of move, is this not possible? It's not reading the alignment variable. Thanks

 

 

^C^C-insert;\\;;;_.-bedit;$M=$(getvar,insname);_dview;all;;points;;;;_.bparameter;_A;$M$(getvar,target);_Perpendicular;0,1;_BSAVE;_BCLOSE;

 

^C^C-insert;\\;;;_.-bedit;$M=$(getvar,insname);_zoom;extents;viewctr;_.bparameter;_A;$M$(getvar,viewctr);_Perpendicular;0,1;_BSAVE;_BCLOSE;

 

 

Command: _.bparameter
Enter parameter type [Alignment/Base/pOint/Linear/Polar/Xy/Rotation/Flip/Visibility/looKup]: _A
Specify base point of alignment or [Name]:
Point or option keyword required.
Specify base point of alignment or [Name]: *Cancel*

0 Likes
Message 13 of 17

hmsilva
Mentor
Mentor

Hi m_rogoff,

 

as I said in message #8 I could not find way to run the macro at once, only in two separeted macros, works as expected...

^C^C-insert;\\;;;_.-bedit;$M=$(getvar,insname);

 to insert the block, and open block editor, and

^C^C_dview;all;;points;;;;;_.bparameter;_A;$M=$(getvar,target);;_Perpendicular;@5<90;_BSAVE;_BCLOSE;

 to add the alignment parameter, save and close.

 

Uniting the two macros, AutoCAD is not reading the block editor display variables, I did try to add a zoom, a regen, aregenall, a bsave, a line, a point, etc, triing to force AutoCAD to update the display system variables, unsuccessfully.

Perhaps someone else, have other approach to force the display system variables update.

 

Henrique

EESignature

Message 14 of 17

m_rogoff
Advocate
Advocate

I think I got what I need to accomplish my goal now. Thank you all for your help, it's much appreciated. It was really a collaborative effort of elite members. I could not have done this without the out-of-the-box thinking and steering me in differnt directions than my original plan.

 

 

One last question (hopefully). When I use macro  ^C^C-bedit;<current drawing>;   it returns a message: "The name cannot be longer than 255 characters." I got this even after copying the file to my desktop. I am not sure where all the characters are comming from. Thanks

0 Likes
Message 15 of 17

hmsilva
Mentor
Mentor

@m_rogoff wrote:

One last question (hopefully). When I use macro  ^C^C-bedit;<current drawing>;   it returns a message: "The name cannot be longer than 255 characters." I got this even after copying the file to my desktop. I am not sure where all the characters are comming from. Thanks


Unfortunately, and as fas as I know the -BEDIT command don't have the <current drawing> option, just the existing blocks...

In a new dwg,

 

Command: -bedit
Enter block name or [?]: ?
Enter block(s) to list <*>: *
No blocks found.

Command:

 

The current drawing was not listed...

I don't  know what AutoCAD is interpreting with <current drawing>...

 

Henrique 

EESignature

0 Likes
Message 16 of 17

m_rogoff
Advocate
Advocate

I thought it would work like the BEDIT command (full menu). See attached pic. 

 

Selecting <current drawing> from the full menu will open all contents of the drawing in the block editor. When I run this in a macro it gets hung up with the error message described above. Typing <current drawing> into the command line returns same error message.

0 Likes
Message 17 of 17

hmsilva
Mentor
Mentor

@m_rogoff wrote:

I thought it would work like the BEDIT command (full menu). See attached pic. 

 

Selecting <current drawing> from the full menu will open all contents of the drawing in the block editor. When I run this in a macro it gets hung up with the error message described above. Typing <current drawing> into the command line returns same error message.


Yes, It was also what I thought.

But, there is no <current drawing> option at the command line version, only at BEDIT command.

I did also type at the command line, and I get the same error msg...weird...

 

Henrique

 

EESignature

0 Likes