How to Change Appearance of a solid Body in IPT in IAM Level?

How to Change Appearance of a solid Body in IPT in IAM Level?

BeKirra
Advisor Advisor
392 Views
4 Replies
Message 1 of 5

How to Change Appearance of a solid Body in IPT in IAM Level?

BeKirra
Advisor
Advisor

I know the appearance in IPT can be manually changed in IAM level without modifying the IPT.

 

However, in my case, I prefer to change the appearance in certain solid body in IPT if it has multi solid bodies.

(I guess it will require user to select the solid).

 

I find similar topics in the iLogic forum but not match what I need.

Thanks for your help.

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
393 Views
4 Replies
Replies (4)
Message 2 of 5

Michael.Navara
Advisor
Advisor

This code snippet can help you. 

Sub Main()
    Dim body As SurfaceBody
    Dim pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick a body")
    Dim surfaceBodyProxy As SurfaceBodyProxy = TryCast(pick, SurfaceBodyProxy)
    If Not surfaceBodyProxy Is Nothing Then
        body = surfaceBodyProxy.NativeObject
    Else
        body = pick
    End If
    ChangeAppearance(body)
    ThisApplication.ActiveDocument.Update()
End Sub

Private Sub ChangeAppearance(body As SurfaceBody)
    Dim partDef As PartComponentDefinition = body.Parent
    Dim partDoc As PartDocument = partDef.Document
    Dim assetNames = partDoc.AppearanceAssets.OfType(Of Asset).Select(Function(x) x.DisplayName)
    Dim selectedAssetName As String = InputListBox("Select Appearance", assetNames).ToString()

    Dim selectedAsset As Asset = partDoc.AppearanceAssets.OfType(Of Asset).FirstOrDefault(Function(x) x.DisplayName = selectedAssetName)
    If selectedAsset Is Nothing Then Return

    body.Appearance = selectedAsset

End Sub

 

0 Likes
Message 3 of 5

BeKirra
Advisor
Advisor

Sorry, for the late response.

And thanks for your help.

 

Can the code not modify the part file when changing the appearance?

I'd like keep the part file or sub-assembly as it is.

 

Also, can "Inventor Material Library" be available in the list box?

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes
Message 4 of 5

Michael.Navara
Advisor
Advisor

The code snippet can be modified to change appearance of SurfaceBodyProxy at the assembly level.

If you want to add content of appearance library it is easy but you need to ensure the selected appearance to copy to the document before you assign them to the body.

See Set the appearance of an occurrence API Sample for more information.

Sub Main()
    Dim bodyProxy As SurfaceBodyProxy
    Dim pick = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartBodyFilter, "Pick a body")
    Dim surfaceBodyProxy As SurfaceBodyProxy = TryCast(pick, SurfaceBodyProxy)
    If Not surfaceBodyProxy Is Nothing Then
        bodyProxy = surfaceBodyProxy
    Else
        Return
    End If

    ChangeAppearance(bodyProxy)

    ThisApplication.ActiveDocument.Update()
End Sub

Private Sub ChangeAppearance(bodyProxy As SurfaceBodyProxy)
    Dim asmDef As AssemblyComponentDefinition = bodyProxy.ContainingOccurrence.ContextDefinition
    Dim asmDoc As AssemblyDocument = asmDef.Document
    Dim assetNames = asmDoc.AppearanceAssets.OfType(Of Asset).Select(Function(x) x.DisplayName)
    Dim selectedAssetName As String = InputListBox("Select Appearance", assetNames).ToString()

    Dim selectedAsset As Asset = asmDoc.AppearanceAssets.OfType(Of Asset).FirstOrDefault(Function(x) x.DisplayName = selectedAssetName)
    If selectedAsset Is Nothing Then Return

    bodyProxy.Appearance = selectedAsset

End Sub

 

0 Likes
Message 5 of 5

BeKirra
Advisor
Advisor

@Michael.Navara wrote:

The code snippet can be modified to change appearance of SurfaceBodyProxy at the assembly level.

If you want to add content of appearance library it is easy but you need to ensure the selected appearance to copy to the document before you assign them to the body.

See Set the appearance of an occurrence API Sample for more information.


 

Sorry, I am new to iLogic.

Have looked your link to HELP but have no idea how to make it works.

 

Please mark "Accept as Solution" and "Like" if my reply resolves the issue and it will help when others need helps.
= ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ = ♪ = ♫ =
A circle is the locus of a cursor, starting and ending at the same point on a plane in model space or in layout such that its distance from a given coordinates (X,Y) is always constant.
X² + Y² = C²
0 Likes