Hello all,
I'm having the hardest time figuring out what OBD (v10.05.00.049) wants me to call the "Sheet Number" model property through VBA. I've set up a search criteria to scan all my tags in my drawing. When it gets to the drawing number tag, I want it to take that value and apply it to the model property "Sheet Number". It's not working for "SheetNumber", but if I replace "SheetNumber" with "Name" or "Description" it works as expected so I think the code it getting the definitions of "MyModel" correctly. Another odd thing is if I type "sheetnumber", the VBA editor capitalizes it to "SheetNumber", so I think it recognized it. Any help would be much appreciated. Thanks!
If Tag.TagDefinitionName = "drawing_number" Then MyModel.SheetNumber = Tag.Value End If
Amador
SheetNumber isn't part of the MicroStation VBA ModelReference class, but it is part of the SheetDefinition class. How is your variable MyModel declared?
SheetNumber
ModelReference
SheetDefinition
MyModel
Regards, Jon Summers LA Solutions
Hi Amador,
Amador Ontiveros said:I've set up a search criteria to scan all my tags in my drawing
Not important for the discussion how to change the sheet parameters ;-)
Amador Ontiveros said:Another odd thing is if I type "sheetnumber"
API naming and MicroStation GUI are different, I assume because of history and MicroStation features development. It can be confusing, but right "mapping" can be found easily.
Amador Ontiveros said:Any help would be much appreciated.
This should work:
Public Sub ChangeSheetParams() If ActiveModelReference.Type <> msdModelTypeSheet Then Exit Sub End If Dim sheetDef As SheetDefinition Set sheetDef = ActiveModelReference.GetSheetDefinition ' Set sheet number sheetDef.SheetName = "Whatever number" ' Set sequence number sheetDef.SheetNumber = 9999 ' Save changes back to the sheet definition ActiveModelReference.SetSheetDefinition sheetDef End Sub
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Answer Verified By: Amador Ontiveros
Hi Jon, MyModel is declared as follows
Dim MyModel As ModelReference Dim MySheetDef As SheetDefinition Set MyModel = ActiveModelReference Set MySheetDef = MyModel.GetSheetDefinition
Thank you for your reply Jan! I understand what you've presented but I'm starting to think the sheet number is part of a different definition in OpenBuilding. Notice the debugger highlighted ".SheetNumber" as the error.
the debug highlights a part of the code that seems correct so I checked all the options for "MyModel" and notice "SheetNumber" is not included.
Maybe this is a glitch in the version of OpenBuilding that I'm using, as my company has not upgraded to the latest build.
Amador Ontiveros said:the sheet number
Because of confusing naming (different in GUI and in API), I recommend to post picture what "sheet number" do you mean.
Amador Ontiveros said:is part of a different definition in OpenBuilding
It cannot be, but I guess only the picture (I have not OBD installed) can confirm you mean "sheet number" from MicroStation and not "sheet number" used by OBD in different context. But I do not think it's the case.
Amador Ontiveros said:Notice the debugger highlighted ".SheetNumber" as the error.
Of course it does. As Jon wrote, sheet number (as well as all other sheet properties) is not part of model data structure. It means you cannot access properties like sheet number, sheet name etc. using model reference (it just not makes sense). The right way, as demonstrated in my code, is to obtain SheetDefinition object at first.
Amador Ontiveros said:Maybe this is a glitch in the version of OpenBuilding that I'm using
I am pretty sure it's not.
Why do you not try my code, extract SheetDefinition, to change SheetName property (displayed as "Sheet number" in GUI) in this object and to assign it back to the model?
Here is the image Jan
Jan Šlegr said:Of course it does. As Jon wrote, sheet number (as well as all other sheet properties) is not part of model data structure. It means you cannot access properties like sheet number, sheet name etc. using model reference (it just not makes sense). The right way, as demonstrated in my code, is to obtain SheetDefinition object at first.
If i change the code to
If Tag.TagDefinitionName = "drawing_number" Then MyModel.Description = Tag.Value End If
It does write back to the "Description" column in the GUI, so I'm not sure I follow... I posted in my reply to Jon that I used ".GetSheetDefinition". I will start a new VBA session to test your code as is to see if it writes back.
Thanks again for help with this!
Amador Ontiveros said:It does write back to the "Description" column in the GUI, so I'm not sure I follow
What is not clear and what you do not follow?
Description is ModelReference property.
SheetNumber, SheetName etc. are SheetDefinition properties.
Regards,
Thanks Jan, it's working! One was a blatant error on my part. I was lacking the following code to write back to the definition.
ActiveModelReference.SetSheetDefinition MySheetDef
The other part isn't a glitch, but as you stated
Jan Šlegr said:Because of confusing naming
OpenBuildings labels the value as "Sheet Number" in every GUI, but the code needed to call out "Name", as follows
If Tag.TagDefinitionName = "drawing_number" Then MySheetDef.SheetName = Tag.Value ActiveModelReference.SetSheetDefinition MySheetDef End If
Because of the inconsistency with naming I couldn't follow which value was model property and which was sheet definition. I apologize, I'm an end user with no formal training in VBA or Microstation code.
Thanks again for your help, I've marked your previous reply with the correct code as the correct answer.
Amador Ontiveros said:Because of the inconsistency with naming I couldn't follow which value was model property and which was sheet definition.
It's simple, use Debug to compare values in GUI and values available in code:
Amador Ontiveros said:I'm an end user with no formal training in VBA or Microstation code.
It's hard to write a code in such case. You should buy and read Learning MicroStation VBA book at least. Even when it's quite old and written for V8i, the most of its content is still valid, because VBA API did not change too much between V8i and CE.