Hi All,
Having a problem with setting a tag value through VBA.
I want to only set a single TagSet, but it has the same name as another set placed on the design already.
The Cell is called "DM1" and contains a TagSet called "Deco". This cell needs to be placed many times on the same design. I thought about using tags to try to store additional information in each cell that i can then extract with VBA.
Problem i have is that i can set the tag value once when placing the cell. When i place the next cell the values don't change (as I'm assuming its "resetting" the first cell's tags)
I can also get VBA to change all of the TagSet values in the entire design at once, but this is not wanted as the information i'm wanting to store is for that particular cell, not all of them.
Is there a way - through VBA - that you can update TagSet values in a selected element?
I have looked around the forums and have tried a few things but nothing is giving me the exact answer im looking for.
I'm hoping that i can do something along of the lines of when placing the cell, i can use GetLastValidElement and run a SetTag command on it, which won't affect the rest of the Tags.
I have come up with a bit of code, but removed all the SetTags part as i think its wrong... hoping someone can point me in the right direction.
Dim oMSG As CadInputMessageDim oLastElement As ElementPlaceAgain:Set oMSG = CadInputQueue.GetInput()Do While oMSG.InputType <> msdCadInputTypeReset If oMSG.InputType = msdCadInputTypeDataPoint Then CadInputQueue.SendDataPoint oMSG.Point Set oLastElement = ActiveModelReference.GraphicalElementCache.GetLastValidElement 'Set Tag Values for oLastElement (1st Tag with Value of sString1, 2nd Tag with Value of sStrign 2 etc) GoTo PlaceAgain ElseIf oMSG.InputType = msdCadInputTypeReset Then CadInputQueue.SendReset CommandState.StartDefaultCommand End IfLoop
Cheers!
Rob
Hi Rob,
Unknown said:I want to only set a single TagSet, but it has the same name as another set placed on the design already.
What exactly does it mean? Tags are groupped into Tag Sets, which work as templates. Different Tag Sets with the same name cannot exist in the same design file. Of course the same Tag Set can be attached to many elements and Tags can have different values (but because they are created based on the same template, they all have the same structure and behaviour).
Unknown said:The Cell is called "DM1" and contains a TagSet called "Deco". This cell needs to be placed many times on the same design. I thought about using tags to try to store additional information in each cell that i can then extract with VBA.
It's for 100% valid request and correct idea, I use this approach in several customers' macros too.
Unknown said:Problem i have is that i can set the tag value once when placing the cell. When i place the next cell the values don't change (as I'm assuming its "resetting" the first cell's tags)
That's because your code looks weird. What I think you should do:
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Unknown said: What exactly does it mean? Tags are grouped into Tag Sets, which work as templates. Different Tag Sets with the same name cannot exist in the same design file. Of course the same Tag Set can be attached to many elements and Tags can have different values (but because they are created based on the same template, they all have the same structure and behaviour).
What exactly does it mean? Tags are grouped into Tag Sets, which work as templates. Different Tag Sets with the same name cannot exist in the same design file. Of course the same Tag Set can be attached to many elements and Tags can have different values (but because they are created based on the same template, they all have the same structure and behaviour).
My bad, worded that wrong. I want to change a Single tagSet... not tag.
Hopefully this image is of some help.
All cells below are identical (cell is DM1)... when the Cell was created i attached the tagSet "Deco" which contains 3 tags.
The values in the tags are set based on inputs from VBA (i have that part all working). Once the Value for the tags are set, they should not change until removed from the design.
BUT... i need to place the exact same cell (DM1) onto the design numerous times after the first one is placed, however the Tag values must be different
Unknown said: That's because your code looks weird. What I think you should do: Implement cell placement in "standard VBA way", which means to implement IPrimitiveCommand class. In IPrimitiveCommandEvents_DataPoint event, you will write your cell into design file. Next step will differ a bit if the cell has tags attached already (tags were attached when the cell was created in a cell library) or if you have to attach tag set to the cell. With regards, Jan
Thanks Jan, i will try IPrimitiveCommand.... i have only ever used Primitives once (based on the advice of another user on this forum) but will give it a go!
Unknown said: Hopefully this image is of some help. All cells below are the identical (cell is DM1)... when the Cell was created i attached the tagSet "Deco" which contains 3 tags.
Hopefully this image is of some help. All cells below are the identical (cell is DM1)... when the Cell was created i attached the tagSet "Deco" which contains 3 tags.
Yes, it's clear now. It means the situation is quite standard and in my opinion it's the most simple case comparing to other options, because the tags are attached to the cell already.
Unknown said:i will try IPrimitiveCommand.... i have only ever used Primitives once (based on the advice of another user on this forum) but will give it a go!
If you did it once, you will do it again, I am sure :-)
I recommend to check examples in MicroStation VBA help, e.g. "Line Element Creation Command" example is quite close to what you need to do.
A notice:
You have to write the cell at first and to change tags value in the second step, not in the inverse order. It's because tags cannot be attached to element that doesn't exist in design file already. So if you create cell object using some from CreateCellElement methods, tags in fact doesn't exist (or are not accessible) despite of they are attached to the cell in the cell library. After ActiveModelReference.AddElement is used, MicroStation does all steps required to attach tags to written cell exactly as it was in the cell library automatically. And it's the right time to change tags values.
HTH Jan
Unknown said: I will try IPrimitiveCommand
There are plenty of examples in VBA help, and here's a create shape example. As Jan wrote, when you place a cell that contains tags, the tags are copied from the cell definition and placed as new elements in the DGN model. You need to edit those new tag elements to assign them the right values. ShapeTagger shows how to update tags on an element.
This tag data overview may help.
Unknown said:Hopefully this image is of some help
An illustration is often useful. A DGN model is usually better, because then we can poke around. In this instance, it's hard to read dark blue text on a black background — it would be so much easier to read had you used a white background for your DGN model.
Regards, Jon Summers LA Solutions