.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Checking whether a PointGroup and PointStyle exists for COGO Points

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
lee.morse
336 Views, 6 Replies

Checking whether a PointGroup and PointStyle exists for COGO Points

Hi,

 

I have been reading through the documentation, but I cannot see how to check if a COGO Point PointGroup or a PointStyle already exists in the collection.

 

https://help.autodesk.com/view/CIV3D/2024/ENU/?guid=GUID-F5C897B7-07D9-47F3-B411-43CE9FEDA050 

 

https://help.autodesk.com/view/CIV3D/2024/ENU/?guid=GUID-6D1BC307-1824-4B66-9B62-8C7AECB130DC 

 

If I add a PointGroup or PointStyle that already exists an exception is thrown.

ObjectId pointGroupID = CivilApplication.ActiveDocument.PointGroups.Add("CS");                                                      
PointGroup pointGroup = pointGroupID.GetObject(OpenMode.ForRead) as PointGroup;
ObjectId pointStyleId = CivilApplication.ActiveDocument.Styles.PointStyles.Add("Survey Underground");
PointStyle pointStyle = pointStyleId.GetObject(OpenMode.ForWrite) as PointStyle;

 

Does anyone know how to check if the Group and Style exists?

 

Thanks

Labels (1)
6 REPLIES 6
Message 2 of 7
norman.yuan
in reply to: lee.morse

Both PointGroupCollection (CivilDocument.PointGroups property) and PointStyleCollection (CivilDOcument.Styles.PointStyles property) has overloaded method Contains(). Use it to test if a PointStyle/PointGroup already exists or not:

 

if (!CivilApplication.ActiveDocument.PointGroup[Styles.PointStyles].Contains("MyPtGroup[MyPtStyle]"))

{

    // Add new PointGroup/Style here...

}

 

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 7
lee.morse
in reply to: norman.yuan

Ah! Perfect. Thank you.

 

How do I now grab the ID of an existing PointGroup\PointStyle?

 

 pointStyleId = CivilApplication.ActiveDocument.PointGroups.???("CS")
Message 4 of 7
norman.yuan
in reply to: lee.morse

If you browse the 2 collection classes in VS' Object Browser, you could have EASILY found the answer to your question (including the one you asked originally): both class has this[ObjectId] and this[string] properties. So, you do:

 

var groupId = ObjectId.Null

if (CivilApplication.ActiveDocument.PointGroups.Contains("xxxx"))

{

    groupId=CivilApplication.ActiveDocument.PointGroups["xxxx"]

}

else

{

    groupId=CivilApplication.ActiveDocument.PointGroups.Add("xxxx");

}

 

The same is with PointStyles.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 5 of 7
lee.morse
in reply to: norman.yuan

Thanks @norman.yuan ,

 

I am only just beginning, my knowledge is lacking in a lot of areas. I did find this before posting, but my coding knowledge is not good enough, I find this a bit inscrutable:

 

(are you able to educate me in what I should have been looking for in the decompiled class?)

 

public class PointGroup : DBObject
    {
        public unsafe UDPClassificationApplyType UDPClassificationApplyType
        {
            get
            {
                //IL_0028: Expected I, but got I8
                //IL_0040: Expected I, but got I8
                //IL_0040: Expected I, but got I8
                UDPClassificationApplyType uDPClassificationApplyType = UDPClassificationApplyType.Custom;
                AeccAttribute.ATTRTYPE aTTRTYPE = (AeccAttribute.ATTRTYPE)167772160;
                AeccAttribute aeccAttribute;
                _003CModule_003E.AeccAttribute_002EAttrVal_002Econstruct((AeccAttribute.AttrVal*)(&aeccAttribute), &aTTRTYPE);
                System.Runtime.CompilerServices.Unsafe.As<AeccAttribute, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref aeccAttribute, 24)) = 167780383;
                try
                {
                    AeccDbPG* ptr = (AeccDbPG*)((ulong)(nint)GetImpObj() + 24uL);
                    long num = *(long*)(*(long*)ptr + 8);
                    long _imp__003FkNull_0040AeccUserParam_0040_00402V1_0040A = System.Runtime.CompilerServices.Unsafe.As<AeccUserParam*, long>(ref _003CModule_003E.__imp__003FkNull_0040AeccUserParam_0040_00402V1_0040A);
                    if (((delegate* unmanaged[Cdecl, Cdecl]<IntPtr, AeccAttribute*, AeccUserParam*, int>)num)((nint)ptr, &aeccAttribute, (AeccUserParam*)_imp__003FkNull_0040AeccUserParam_0040_00402V1_0040A) != 0)
                    {
                        AeccAtom aeccAtom;
                        *(int*)(&aeccAtom) = *(int*)(&aeccAttribute);
                        try
                        {
                            uDPClassificationApplyType = ((87 == *(int*)(&aeccAtom)) ? UDPClassificationApplyType.None : ((3751 != *(int*)(&aeccAtom)) ? uDPClassificationApplyType : UDPClassificationApplyType.All));
                        }
                        catch
                        {
                            //try-fault
                            _003CModule_003E.___CxxCallUnwindDtor((delegate*<void*, void>)(delegate*<AeccAtom*, void>)(&_003CModule_003E.AeccAtom_002E_007Bdtor_007D), &aeccAtom);
                            throw;
                        }
                    }

                    GC.KeepAlive(this);
                }
                catch
                {
                    //try-fault
                    _003CModule_003E.___CxxCallUnwindDtor((delegate*<void*, void>)(delegate*<AeccAttribute*, void>)(&_003CModule_003E.AeccAttribute_002E_007Bdtor_007D), &aeccAttribute);
                    throw;
                }

                _003CModule_003E.AeccAttribute_002EfreeContents(&aeccAttribute);
                System.Runtime.CompilerServices.Unsafe.As<AeccAttribute, int>(ref System.Runtime.CompilerServices.Unsafe.AddByteOffset(ref aeccAttribute, 24)) = 0;
                return uDPClassificationApplyType;
            }
        }



etc
etc
etc
...

 

 

 

Message 6 of 7
Jeff_M
in reply to: lee.morse

@lee.morse why are you decompiling? Check the API Documentation for exposed properties and methods: https://www.autodesk.com/civil3d-developer-net-reference-2024 

 

Also, the programmers who focus on the C3D API can be found HERE and is where you should post C3D related quetsions.

 

Jeff_M, also a frequent Swamper
EESignature
Message 7 of 7
lee.morse
in reply to: Jeff_M

Roger that, thank you

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report