見出し画像

Inventor / iLogic : マルチソリッドを色分けするルール

構想設計時などでマルチソリッドを作る場合があります。その時、各ソリッドを区別するために色分けをします。ソリッドの数が増えてくると、いちいち色分けするのが面倒です。そこで、ソリッドを色分けするルールを作りました。

アクティブなドキュメントに含まれている外観をランダムに選択して、各ソリッドのボディにその外観を設定します。

'マルチソリッドを色分けする

    ' Ver 1.0 By Yoji Tanaka At 22/05/27 

    Dim oDoc As Inventor.PartDocument = ThisDoc.Document
    Dim oSFBody As Inventor.SurfaceBody
    Dim AprAssetCout As Integer = oDoc.AppearanceAssets.Count
    Dim oAprAsset As Inventor.Asset
    Dim ColorIndx As Integer
	Try
		Dim MyView As DesignViewRepresentation = oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Item("BODY_COLORMAP")
	Catch ex As Exception	
		Dim MyView As DesignViewRepresentation = oDoc.ComponentDefinition.RepresentationsManager.DesignViewRepresentations.Add("BODY_COLORMAP")
	End Try
	
    For Each oSFBody In oDoc.ComponentDefinition.SurfaceBodies
		ColorIndx = Round(AprAssetCout * Rnd())
		If ColorIndx = 0 Then ColorIndx = AprAssetCout
        oAprAsset = oDoc.AppearanceAssets.Item(ColorIndx)
        oSFBody.Appearance = oAprAsset
    Next
	
	MessageBox.Show("DONE!", "BODY_COLORMAP")

下の図は、ソリッドを矩形上に配列したものです。

ここに色分けのルールを実行すると、

の様に色分けされます。

色分けは、「BODY_COLORMAP」の名前のデザインビューに保存されます。このデザインビューを削除すると、色分けも削除されます。

※ このルールを改良したものを作成しました。以下に紹介をしていますので、そちらのほうを利用ください。


役に立った!という記事にはぜひサポートお願いします。サポート頂けると大変に励みになります。