Profile, Profile View, and LabelSetId #
When you create a Profile via Profile.Create
API, you need to specify a ProfileSetId
, so how can you obtain the ProfileSetId
from the code?
This could be important if you are creating an Offset Profile
, and you want it to have the same LabelSetId
as its parent Profile.
The answer is that you can’t, because there is not such thing as the ProfileSetId
for a Profile
.
All you have is that you have a ProfileSet
for a Profile
in a Profile View
. Yes, a ProfileSet
( and hence, ProfileSetId
) is depending on both the Profile
and Profile View
.
Since a Profile View
can have multiple Profiles
, you will need to set their individual LabelSet
in the Profile View Properties, as shown in the following screenshot:
How to obtain the LabelSetId for a Profile in a Profile View? #
To obtain the LabelSetId
for a Profile
in a Profile View
, you will need to pass in both the Profile View
ObjectId
and Profile
ObjectId
. Here’s the code that you can use to do this.
private static void Transact(Action<Transaction> action)
{
var doc = Application.DocumentManager.MdiActiveDocument;
using var tr = doc.TransactionManager.StartTransaction();
action(tr);
tr.Commit();
}
public static T GetObject<T>(this Transaction ts, ObjectId objectId, OpenMode openMode = OpenMode.ForRead)
where T : DBObject
{
return ts.GetObject(objectId, openMode) as T;
}
[CommandMethod(nameof(ReadProfileLabelSets))]
public void ReadProfileLabelSets()
{
Transact(ReadProfileLabelSetMethod);
}
private void ReadProfileLabelSetMethod(Transaction ts)
{
var alignmentIds = CivilApplication.ActiveDocument.GetAlignmentIds();
var lblgrpClass = RXObject.GetClass(typeof(ProfileLabelGroup));
foreach (ObjectId alignmentId in alignmentIds)
{
var alignment = ts.GetObject<Alignment>(alignmentId);
var profileIds = alignment.GetProfileIds();
foreach (ObjectId profileId in profileIds)
{
var profileViewIds = alignment.GetProfileViewIds();
foreach (ObjectId profileViewId in profileViewIds)
{
var allPointLabelGroup = ProfileHorizontalGeometryPointLabelGroup.GetAvailableLabelGroupIds(profileViewId, profileId);
var lblgrpIds = ProfileLabelGroup.GetAvailableLabelGroupIds(lblgrpClass, profileViewId, profileId, true);
}
}
}
}