For all issues regarding the Forums use, please, refer to the Forum Rules.

Our Solutions

Need professional assistance?
Consider our:

Support Offerings


Need to speed up your development?
Have a look at our:

Samples & Tools


Need some functionality extending standard OCCT capabilities?
Check out our:

Adv. Components

Related pages

Splitting STEP files in sub parts

davide's picture

HI. I'm using OCC 6.2 .net wrapper.
My goal is to load a STEP file and split it into several STEP with model structure.
The problem is that i don't know how to get the original part names:
The model structure is ok but all names changed in : "Open CASCADE STEP translator 6.2 8 xxxx" .

Here is the sub i use to read the main step file
Dim r As New STEPCAFControl.Reader

Dim D As New TDocStd.Document(New TCollection.ExtendedString("MDTV-CAF"))

If r.Transfer(D) Then

Dim ROOT As XCAFDoc.ShapeTool = XCAFDoc.DocumentTool.ShapeTool(D.Main)
Dim Colors As XCAFDoc.ColorTool = XCAFDoc.DocumentTool.ColorTool(D.Main)
Dim labels As New TDF.LabelSequence
Dim labelsCols As New TDF.LabelSequence

For ic As Integer = 1 To labelsCols.Length
Dim labelc As TDF.Label = labelsCols.Value(ic)
' MsgBox(GetName(labelc))
Dim tn1 As TreeNode = Nothing
Dim tn2 As TreeNode = Nothing
Dim ts As syShape = Nothing
Dim nRoots As Integer = labels.Length
For i As Integer = 1 To nRoots
Dim label As TDF.Label = labels.Value(i)
' MsgBox(GetName(label))

If XCAFDoc.ShapeTool.IsAssembly(label) Then
Nodi.Text = GetName(label)
recurse(label, Nodi, Colors, r)

MsgBox("nessun assieme trovato")

End If

End If

here is the sub that recurse the structure

Public Sub recurse(parentLabel As TDF.Label, tNode As TreeNode, Colors As XCAFDoc.ColorTool, r As STEPCAFControl.Reader)
'Dim parentLabel As TDF.Label = node.Father.Label
Dim Livello As Integer = 0
contaParent(tNode, Livello)

If parentLabel.HasChild Then
Dim nodeIterator1 As New TDF.ChildIDIterator(parentLabel, XCAFDoc.General.ShapeRefGUID(), True)
While nodeIterator1.More
Dim node1 As TDataStd.TreeNode = CType(nodeIterator1.Value, TDataStd.TreeNode)
Dim questo1 As XCAFDoc.ShapeTool = XCAFDoc.DocumentTool.ShapeTool(node1.Label)
'Dim labels2 As New TDF.LabelSequence
Dim Shp2 As TopoDS.Shape = XCAFDoc.ShapeTool.GetShape(node1.Label)
Dim tn2 As New TreeNode
If Not Shp2.IsNull Then
'Dim appo As String = tNode.Parent
Dim ts As syShape = Me.addSyShape(node1.Label, Shp2, Colors, Livello, r)

tn2 = tNode.Nodes.Add(ts.Id, ts.Name)
tn2.Tag = ts
tn2.ToolTipText = CType(tn2.Tag, syShape).Id

End If
If node1.HasFather Then
recurse(node1.Father.Label, tn2, Colors, r)

End If
End While

End If
Dim theFileName As String = IO.Path.GetDirectoryName(_tmpFile) & "\" & thisShape.Name & ".STP"
'Dim w1 As New STEPControl.Writer(r.Reader_.WS, True)
Dim w1 As New STEPControl.Writer()
w1.Transfer(shp, STEPControl.StepModelType.AsIs, True)
End Sub

thank you

here is the sub that write the STEPs