Adding Class members through automation

A

Agis

I'm trying to create UML class diagrams in Visio through automation. I use a
function that expects the name of a parent and child class. This function
then tries to create the classes like this:

loParent = Page.Shapes(tcParentName)

If this does not result in a error, loParent hold the existing Parent class
in the UML diagram. If an error occurs the Parent doesn't exist and is
created. This works fine, but I expect there is a cleaner method, something
like FindShape but I haven't found it, can anyone tell me?

After I created the classes and the Generalization between them, I'd like to
add Attributes and Operations. I haven't found out how that is done. I can
get the shapes with code like this:

loAttributes = loParent.Shapes('Attributes')

And if Attributes are added in Visio, I can see them in:

loAttributes.Characters.Text

but I can't set them. I tried setting the Text property to a string I build,
but that results in an error: "Required operation is presently disabled."
 
W

Wei-Dong XU [MSFT]

Hi,

So far as I know, for finding one shape, we will need to write one function
on this by looping the shapes collection.

For the attribute modification, could you be so kind to give me one repro
steps? I will research this for you then.

Look forward to your reply. My pleasure to be of any assistance!

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei-Dong XU [MSFT]

Hi,

Based on my research on the error message "Required operation is presently
disabled", the Text property only returns the text of the Characters. We
can't use this to change the texts. As I know, we will need to change the
Attribute from UI.

Please feel free to let me know if any question. It is my pleasure to be of
assistance.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Agis

Hi,

OK, so the Text property is readonly. Are you telling me there is no way to
add attributes and operations to the UML Class shape? I can't imagine that to
be true. I guess it is something like AddField, but I wasn't able to find
this out. Maybe you can?
 
W

Wei-Dong XU [MSFT]

Thanks for the reply!

Currently I am still researching this issue for you. If any idea, I will
update here at the first time.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei-Dong XU [MSFT]

Hi Agis,

At the shape you are going to edit, its text is locked by Visio. This is
the protection of Visio to avoid the modification from automation. So for
updating it, we will need to unlock it. The sample code is:
'-------------------------------
loAttributes = loParent.Shapes('Attributes')
loAttributes.Cells("LockTextEdit") = 0 'unlock the text
loAttributes.Characters.Text = "-567 : bool"
loAttributes.Cells("LockTextEdit") = 1 'lock the text again
'-------------------------------

This way, we can change the Text in the visio UML Class diagram without
that error message.

Please feel free to let me know if any question. My pleasure to be of any
assistance.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Agis

Hi,

Thanks, I'll give it a try. I have to concatenate the string with Attributes
and Operations myself before setting the Text properties. It will work, but
I'd be very surprised if there wasn't a way to Add a member with COM.
Something like AddField like I mentioned. Can you find this out for sure, or
did you allready do that with this result?
 
A

Agis

Hi,

I've tried it. It looks like it works, but that is only visual. This way of
adding does change the text of the shapes, but if I check the properties of
the Class shape (in Visio interactively) there are no Attributes found. If I
add a Attribute with this property sheet, the newly added Attribute is nog
shown visualy. The Text property apparantly shows the Attributes if the Text
property itself is not set. This means I still need a method to realy add the
Attributes so they can be seen and altered in the property sheet of the
object in Visio.
 
A

Agis

Some extra info: If I add Attributes to a Class interactivly throug Visio I
can see them in the loAttributes.Characters.Text property. With the method
you described below I can now set the Text propertie to an empty string. In
Visio the Attributes are now invisible, but if you check the properies of the
Class you can still see them in the Attributes table.
 
W

Wei-Dong XU [MSFT]

Hi Agis,

Currently I am researching this issue for you. When any idea, I will update
this thread then.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wei-Dong XU [MSFT]

Hi Agis,

Based on my research on this, I have to say that there is no any automation
method/interface currently available for us to change the attribute of
shapes in the drawing for UML solution. Internally Visio prevents the
modification on the attribute text except changing them manually. My
previous code circumvents this protection. However, it still doesn't
actually change the underlying UML model; only the displayed text is
affected.

Now, I store your requirement at Microsoft product feedback site; the
product team will consider this at the future product update or new
version design. Thanks!

If any question, please feel free to let me know. I will be more than happy
to help further.

Best Regards,
Wei-Dong XU
Microsoft Product Support Services
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top