TurboCAD Forums

The Ultimate Resource for TurboCAD Knowledge

Remember to do a search before you ask a question!!!

Custom Properties
Read 4740 times
* June 07, 2010, 04:34:16 AM
Hi Everyone,
I'm trying to set a custom property on several graphics.
After looking in the SDK manual I found this:

Code: [Select]
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:

Code: [Select]
        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"
            .Item("PlotID").Value = "AABBCC99"
        End With

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

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

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

The manual also says:
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:
    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. ;)


Mike C


* June 07, 2010, 10:23:49 AM
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.


.Add("PotID", "")

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




* June 08, 2010, 05:25:28 AM
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


* June 08, 2010, 09:26:58 AM
You're welcome, Mike. The more people that use the SDK, the better all our understanding grows.