Pipe Structure PartSizeName returns wrong information

Pipe Structure PartSizeName returns wrong information

tipitasa
Enthusiast Enthusiast
832 Views
4 Replies
Message 1 of 5

Pipe Structure PartSizeName returns wrong information

tipitasa
Enthusiast
Enthusiast

I'm trying to make a copy of a Structure, so I need to obtain the FamilyId and SizeId from the existing original Structure.

The PartSizeName that I read from the structure differs from anything that can be found in the PartSizes of the Structure PartFamily.

How do I get the correct match to obtain the SizeId from the existing Structure?

using Autodesk.Civil.DatabaseServices;

// structure that is used for the copy
Structure origStructure = tr.GetObject(origStructureId, OpenMode.ForWrite) as Structure;

Network existingNetwork = tr.GetObject(origStructure.NetworkId, OpenMode.ForRead) as Network;
PartsList networkPartsList = tr.GetObject(existingNetwork.PartsListId, OpenMode.ForRead) as PartsList;

// get structure family Id
ObjectId structureFamilyId = networkPartsList[origStructure.PartFamilyName];
PartFamily partFamily = tr.GetObject(structureFamilyId, OpenMode.ForRead) as PartFamily;

// traverse all part sizes in the part family to find size id
structureSizeId = ObjectId.Null;
for (int i = 0; i < partFamily.PartSizeCount; i++)
{
    PartSize partSize = tr.GetObject(partFamily[i], OpenMode.ForRead) as PartSize;
    if (partSize.Name == origStructure.PartSizeName)
     {
        structureSizeId = partSize.Id;
        break;
    }
}


Structure selection during network creation:

tipitasa_1-1702032681174.png

 

Result:

tipitasa_2-1702032747195.png


I have attacthed the basic file with two Pipe Networks.
Using Standard Network works OK, using Storm Network does not.


Moreover, this is possibly a silly question, but why cannot I peek into the Structure object in debug?
I open it normally:

Structure origStructure = tr.GetObject(origStructure, OpenMode.ForRead) as Structure;

And this is what I get:

tipitasa_0-1702031668336.png

What do I need to do to see the parameter values?

0 Likes
833 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

A Part (Structure or Pipe) could have an "invalid" or "orphaned" PartSizeName, that is, the PartSizeName does not match any part in a PartFamily. It is usually caused by a updated/changed part catalog and/or the PartsList is updated, reimported...

 

 When this happens, you would expect user to change the PartSize to a valid PartSize available in the current PartsList. In the coding practice, it usually means that you would call Part.SwapPartFamilyAndSize() to apply an expected PartFamily/PartSize to the part. For example, you could check the drawing to see if there are structures/pipes with this unmatched PartSize; if found, you might want to present a UI to allow user to choose substitute PartSizes for the code to call SwapPartFamilyAndPartSize() method.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

hippe013
Advisor
Advisor

It does seem strange that you are not able to peek inside the structure in debug. 

hippe013_0-1702056515532.png

Instead of...

if (partSize.Name == origStructure.PartSizeName)

Have you tried...

if (partSize.Name == origStructure.PartDescription)

 

 

Message 4 of 5

tipitasa
Enthusiast
Enthusiast

I get this issue using a new document and a new Pipe Network. Can it happen that a PartSizeName is already invaild at creation time, or maybe that I'm not accessing the Parts List in the correct way?

0 Likes
Message 5 of 5

tipitasa
Enthusiast
Enthusiast

I ended up using 

if (partSize.Name == origStructure.Description)

as it seemed to always have the correct Part Size value.

0 Likes