Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X
I'm getting bogged down trying to do something simple.
I'm trying to draw items in a macro, some in "No Pen", some with "Thick" lines and some with white fill
I'm using rectangle, but am having problems both setting the fill type (can't see how this is set) and in getting the pen type to work.
The example below is the simplest way I can show the problem pen problem.
macro testrectangle
Set active pen "No Pen"
create rectangle 9 9 9 19 19 19 19 9
Set active pen "Thick"
create rectangle 10 10 10 20 20 20 20 10
end macro
What I think it should do is draw 1 rectangle in "No Pen" and the 2nd rectangle in "Thick", but what it does is draw both rectangles in thick and thin.
Do rectangles work differently to lines - can't you set the linetype and fill for them in a macro?
Try this.
Macro Test_Rectangle
Select None
Create Rectangle 9 9 9 19 19 19 19 9
Set Active Pen "No Pen"
Select None
Create Rectangle 10 10 10 20 20 20 20 10
Set active pen "Thick"
Select None
End macro
A couple things. When you use set active pen, it not only changes your active pen but also whatever you have selected. Use this to your advantage. Draw the object and then apply the pen.
In your original sample, both pens would be the same because you draw one, change the pen which changes the one you just drew, and then you draw a new one. Use select none a lot.
In regards to the thick/thin, it appears to be a default. You could like make a call to shut off drawing the thick/thin line (check your preferences for this setting). I'm guessing (Haven't tested) that this should resolve it.
Thanks Trevor, helpful as always.
Trouble is that to make my example as simple as possible, I removed a lot of the coding. If I put that back in, along with the "select none"'s that were already there, it still doesn't work.
I start a group before drawing the first bit of geometry, ending it after drawing the last bit. I guess the "select none" command is being ignored if it's inside the "start group" command:
Macro Test_Rectangle
start group
Select None
Create Rectangle 9 9 9 19 19 19 19 9
Set Active Pen "No Pen"
Select None
Create Rectangle 10 10 10 20 20 20 20 10
Set active pen "Thick"
Select None
end group
end macro
Suppose I'll have to add some infos to each bit of geometry and then select them by the infos later to group them. I wonder why do they make things so difficult in IML?
Ah, groups. Yes, I've experimented with those and despised that function. In that case, your approach of selecting after and then grouping likely is the best option. Good luck.
We group items all the time on our drawings, it makes it much easier to move things about, though it doesn't seem to work well inside macros!
Sorry. Should have been more clear. Groups are great by themselves. The problems I mentioned arise when you use the Start Group function and then try to draw or add text within that group. If you want to do something like what you were attempting (two different line types on two objects in one group) that is where I gave up.
My particular instance was simplifying adding multiple part numbers and text in a column format. I wanted the part number bold, text not. I wanted each line grouped with the line above. Couldn't get it to work.
But I agree with you, they are very handy when doing manual moves. I also rely heavily on them for some custom work we've done.
Yes I guessed you were talking about using groups inside macros, I too have given up on them for now - I hope they correct this in a later release.
One thing I didn't follow up though was how do you add fill to a rectangle (or any polygon or ellipse) as you are drawing it? I've tried recording drawing a rectangle and then using the fill window to set white fill, but it only records the drawing of the rectangle, not adding the fill.
Hi tim,
See whether this will be Helpful.........
Macro dsf
Set Active Pen "Thin"
start group
Create Rectangle 9 9 9 19 19 19 19 9
Create Rectangle 10 10 10 20 20 20 20 10
Select None
end group
UNGROUP SELECTION deep
Define el as element
el = activeDoc.firstSelectedElement
el.Rect.segments[1].pen = "Thin"
el.Rect.segments[2].pen = "Thin"
el.Rect.segments[3].pen = "Thin"
el.Rect.segments[4].pen = "Thin"
cut
PASTE same_position
Group selection
End macro
I think after ungrouping you can provide specific attribute values and then select using the attribute values,
apply thin, thick,
then Group
Some Changes
Macro dsf
Set Active Pen "Thin"
start group
Create Rectangle 9 9 9 19 19 19 19 9
Create Rectangle 10 10 10 20 20 20 20 10
Select None
end group
UNGROUP SELECTION deep
Define el as element
el = activeDoc.firstSelectedElement
el.Rect.segments[1].pen = "Thin"
el.Rect.segments[2].pen = "Thin"
el.Rect.segments[3].pen = "Thin"
el.Rect.segments[4].pen = "Thin"
el = el.nextSelectedElement
el.Rect.segments[1].pen = "Thick"
el.Rect.segments[2].pen = "Thick"
el.Rect.segments[3].pen = "Thick"
el.Rect.segments[4].pen = "Thick"
cut
PASTE same_position
Group selection
end macro
Thanks Vaduga
It works but I don't understand why?
You draw the rectangles and group them - OK
You then select none
How does the ungroup selection bit work if nothing is now selected?
Also, what is the cut and paste bit for?
Do you know how to set the fill for selected items within a macro?
Hi Tim,
Select none does not have any effect inside (start group and End group) command. You can remove. I forgot to remove which I previously tested.
After using (el = el.nextSelectedElement) or (el = activeDoc.firstSelectedElement), we cannot use group selection command.
Thats why I used cut and paste to come out of the command.
To my knowledge (I am not sure) There is no command to apply fill. I am trying......