News:

All posts discussing pricing or where to buy TurboCAD will be deleted.

Main Menu

Custom Properties

Started by MikeCrown, June 07, 2010, 04:34:16 AM

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

MikeCrown

Hi Everyone,
I'm trying to set a custom property on several graphics.
After looking in the SDK manual I found this:


Dim gr as Graphic
Dim newProp as Property
Set gr = ActiveDrawing.Graphics.AddSquare 'any old graphic will do
Set newProp = gr.Properties.Add("Weight")
newProp.Value = 10#
Debug.Print "The name of the new property is " & newProp.Name
Debug.Print "The type of the new property is " & prop.Type
Debug.Print "The current value of the new property is " & prop.Value


So after playing around I managed to get this working, but only to a point:

     
       Dim tcCircle, tcProperties As Object
       tcCircle = tcApp.ActiveDrawing.Layers("0").AddCircleCenterAndPoint(0, 0, 0, 0, 0, 0)
       tcProperties = tcCircle.Properties
       With tcProperties
           .Item("BrushStyle").Value = "Solid"
           .Item("BrushColor").Value = -3
           .Item("BrushTransparency").Value = 100
           .Item("PenStyle").Value = "Continuous"
           .Item("PenColor").Value = -3
           .Item("M_Radius").Value = 20
           .Item("Info").Value = "TEST CIRCLE"
           .Add("PlotID")
           .Item("PlotID").Value = "AABBCC99"
       End With


However after running this piece of code to try and detect the value, I get an error:


       For Each tcg As IMSIGX.Graphic In tcApp.ActiveDrawing.Graphics
           MsgBox(tcg.Name)
           For Each tcItem As Object In tcg.Properties
               If tcItem.Name = "PlotID" Then
                   MsgBox(tcItem.Name)
                   Try
                       MsgBox(tcItem.Value)
                   Catch ex As Exception
                       MsgBox(tcItem.Name & " - Error with value")
                   End Try
               End If
           Next
       Next


Its as if the property is being added, but not the value.

The manual also says:
Quote
Note that by setting the Value, the custom property system will automatically detect and set the Type property of the object.  In the case above, the "Weight" property was assigned a Visual Basic double-precision number, so the Type property will return vbDouble.

This may be something to do with it I'm not sure.

I tried adding the property to the graphic non-programmatically through turbocad
Right Click -> Properties -> Custom -> Define... -> Attach...
which worked fine, and then when I ran the Annotate Tool on the drawing the graphic has the property listed:
Quote
   Name: PlotID; Type: 8; Value: AABBCC99

But when I create the property programatically and run the Annotate Tool on that it no longer appears in the list of properites.

Anybody know where I'm going wrong? any help with be gratefully appreciated. ;)

Cheers

Mike C

kchapman

Hi Mike,

Very good question. A little experimentation suggests that you may need to set some starting value of the desired type at the time you add the property. I'll need to update the docs on this method to reflect that the value is not optional.

Change
.Add("PlotID")

to
.Add("PotID", "")

or even
.Add("PlotID", "AABBCC99")

Regards,

Kevan

MikeCrown

Cheers Kevan,

That works great!

You've been a great help with my project so far (as well as others on this forum) ;D

Mike C

kchapman

You're welcome, Mike. The more people that use the SDK, the better all our understanding grows.