Set Tag Values in Selected Element Only

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 CadInputMessage
Dim oLastElement As Element

PlaceAgain:
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 If
Loop

Cheers!

Rob

Parents
  • 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:

    • 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

Reply
  • 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:

    • 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

Children
  • 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).

    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!

  • Hi Rob,

    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.

    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

  • Unknown said:
    Once the Value for the tags are set, they should not change until removed from the design.

    Unfortunately this is the only thing that cannot be asured and the reason why many programmers do not use tags, if consistency is required.

    While the idea of using tags for displayable informations is a good one, you must be aware that each information might be manipulated by the user. Even parts, or the whole tag can be deleted by mistake, so you need a little goodwill. On the other hand, while there are other solutions for storing additional data, it is more difficult to get those data displayed, so if you trust your users that far, tags will be fine.



  • Michael Stark said:

    Once the Value for the tags are set, they should not change until removed from the design.

    Unfortunately this is the only thing that cannot be asured and the reason why many programmers do not use tags, if consistency is required.

    While the idea of using tags for displayable informations is a good one, you must be aware that each information might be manipulated by the user. Even parts, or the whole tag can be deleted by mistake, so you need a little goodwill. On the other hand, while there are other solutions for storing additional data, it is more difficult to get those data displayed, so if you trust your users that far, tags will be fine.

    [/quote]

    I'm undecided on what to do so suggestions are certinitley welcome!

    Basically what i'm trying to achieve, is to somehow store Data on these cells (the bracket and light information) so that when i run my program to scan the drawing for the data, it knows that for those particular cells what the bracket and lights are and can print it into a text file.

    Its for a street light design program i've been asked to modify (but i'm rewriting as the old one was a pain). Tags were the quickest and easiest way i could think of to do it. 

    For each streetlight it contains 3 parts... a pole, bracket and light.

    The easiest thing for me to do is create 3 cells and place them all at the same location at the same time so that the user only sees 1. BUT what if one of them is moved? They all have to move... if i group them then the cell loses its name.

    Once the data is on the drawing, my program then goes and finds the cells and prints the quantity to a text file which is then imported into another program (all of that is already done and working).

    I'm just trying to work out the best way to store the bracket and light information, whilst still being able to easily locate the data when generating the text file.

    I did think about if the tags were deleted. Was going to look at locking them once placed, but then they can't be moved if interfere with other elements.

    If anyone can think of a better or easier way then please let me know!! Any help is greatly appreciated!

  • Unknown said:
    Each streetlight it contains 3 parts... a pole, bracket and light.

    1. Create a Tag Set street-furniture
      • For that Tag Set define Tags pole, bracket and light
    2. Place some lighting cells
      • Attach Tag Set street-furniture to each cellusing MicroStation's Tags toolbox
    3. Use FlexiTable to extract tag data
      • Alternatively, use MicroStation's built-in tag reporting tools

    I've created an example for you. In the attached street-lighting.zip, there's a DGN file. It contains a Tag Set definition, street-furniture having tags as above. The default DGN model has some cell placements with some tags attached. FlexiTable created a tag report and saved it in Excel format.

    Regards, Jon Summers
    LA Solutions

     
    Regards, Jon Summers
    LA Solutions

    street-furniture.zip
  • Thanks Jon,

    Apologies for the delay, have been on leave.

    I will continue to play around with Tags, but from your vast experience, are Tags the best way to go about this? Or is there another way to misc data inside of an element?

    Again i only chose Tags because i don't really know of a better solution so i am interested to see what others think, i would prefer to not refer to any external files and contain all the data inside of the DGN.

  • Unknown said:
    Are tags the best way to go about this?

    I don't know your requirements, so can't comment.

    Here's a review of MicroStation and Databases, which covers both DGN internal and external data.

    Unknown said:
    i only chose Tags because i don't really know of a better solution

    It's best to go for a solution that (a) you understand and (b) is exposed to VBA.  Not all data models are currently possible using VBA.  For example, EC Schemas (i-Models) are pretty new and a C++ API was published in autumn 2012.

     
    Regards, Jon Summers
    LA Solutions

    Answer Verified By: Rob Golding