@Michael.Navara hell yeah ! this worked quite well but another question rises.. I was preparing some snippets in order to see how iLogic behaves before starting actual coding.
AddReference "System.Drawing"
AddReference "Microsoft.Office.Interop.Excel"
Option Explicit On
Option Infer Off
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Imports Microsoft.Office.Interop.Excel
Imports System.Runtime.InteropServices
Imports System.Linq
Imports System.Collections.Generic
Imports System.IO
Imports Autodesk.iLogic.Interfaces
Imports Microsoft.VisualBasic.VBCodeProvider
Sub Main()
Dim partPath1 As String = "\\1.2.3.4\asd\asd\asd\asd\asd\asd\asd\Workspace\asdasd1.ipt"
Dim partPath2 As String = "\\1.2.3.4\asd\asd\asd\asd\asd\asd\asd\Workspace\asdasd2.ipt"
Dim partPath3 As String = "\\1.2.3.4\asd\asd\asd\asd\asd\asd\asd\Workspace\asdasd.ipt"
' Create the parts
CreatePart(partPath1, "Part1")
CreatePart(partPath2, "Part2")
CreatePart(partPath3, "Part3")
' Insert the parts into the current assembly
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition
Dim part1 As ComponentOccurrence = oCompDef.Occurrences.Add(partPath1, ThisApplication.TransientGeometry.CreateMatrix())
Dim part1doc As PartComponentDefinition = part1.Definition
Dim part2 As ComponentOccurrence = oCompDef.Occurrences.Add(partPath2, ThisApplication.TransientGeometry.CreateMatrix())
Dim part2doc As PartComponentDefinition = part2.Definition
Dim part3 As ComponentOccurrence = oCompDef.Occurrences.Add(partPath3, ThisApplication.TransientGeometry.CreateMatrix())
Dim part3doc As PartDocument = part3.Definition.Document
' Mate face of Part1 with Part2
Dim part1Face As Face = part1.SurfaceBodies.Item(1).Faces.Item(1)
Dim part2Face As Face = part2.SurfaceBodies.Item(1).Faces.Item(1)
Dim part3Face As Face = part3.SurfaceBodies.Item(1).Faces.Item(1)
Dim part1workplane As WorkPlane = part1doc.WorkPlanes.Item(1)
Dim part2workplane As WorkPlane = part2doc.WorkPlanes.Item(1)
oCompDef.Constraints.AddFlushConstraint(part1Face , part3Face , 0)
oCompDef.Constraints.AddMateConstraint(part1Face, part2Face, 0, InferredTypeEnum.kNoInference, InferredTypeEnum.kNoInference)
oCompDef.Constraints.AddFlushConstraint(part2Face, part3Face, 0)
oAsmDoc.Update()
End Sub
' Function to create a new part
Sub CreatePart(partPath As String, partName As String)
' Check if the part already exists
If Not System.IO.File.Exists(partPath) Then
' Create a new part
Dim oPartDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, ThisApplication.FileOptions.TemplatesPath & "\Standard.ipt", True)
oPartDoc.DisplayName = partName
' Optionally, add geometry to the part (extrusions, sketches, etc.)
Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition
Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes.Item(3)) ' Create sketch on WorkPlane(3)
Dim tg As TransientGeometry = ThisApplication.TransientGeometry
' Create a rectangle for the sketch
Dim centerPoint As Point2d = tg.CreatePoint2d(0, 0) ' Center point for the rectangle
Dim cornerPoint As Point2d = tg.CreatePoint2d(10, 10) ' Corner point for the rectangle
oSketch.SketchLines.AddAsTwoPointRectangle(centerPoint, cornerPoint)
' Create a profile from the sketch
Dim oProfile As Profile = oSketch.Profiles.AddForSolid() ' Create a profile from the sketch
' Try to create an extrusion with the profile
Try
' Create the extrusion definition
Dim asdExtrudeDefinition As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oSketch.Profiles.AddForSolid(), PartFeatureOperationEnum.kJoinOperation)
asdExtrudeDefinition.SetDistanceExtent(50, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection)' Set the extrusion distance
Dim oExtrusion As ExtrudeFeature = oCompDef.Features.ExtrudeFeatures.Add(asdExtrudeDefinition)' Add the extrusion
Catch ex As Exception
MsgBox("Error during extrusion: " & ex.Message)
Exit Sub
End Try
oPartDoc.SaveAs(partPath, False) ' Save the part
oPartDoc.Close(True)
End If
End Sub
in here this one could give me flush constraint result. why would it work in here not the other ?