trying to extrude a acad dxf by ilogic

trying to extrude a acad dxf by ilogic

mecanicu
Advocate Advocate
129 Views
2 Replies
Message 1 of 3

trying to extrude a acad dxf by ilogic

mecanicu
Advocate
Advocate

Hello.

I made a ilogic code that create a sketch in a part and insert a acad dxf, after that i try to extrude the profiles but inventor cand find any on the sketch. if i try to extrude them manually i cand select the contour or the fill, everything is fine.

here is my code till now :

Sub Main()

    Dim oPartDoc As PartDocument = ThisApplication.ActiveDocument
    Dim oCompDef As PartComponentDefinition = oPartDoc.ComponentDefinition

    ' Șterge schița SketchLitere dacă există
    For Each sk As PlanarSketch In oCompDef.Sketches
        If sk.Name = "SketchLitere" Then
            sk.ExitEdit()
			sk.Delete()
            Exit For
        End If
    Next

    ' Creează schița SketchLitere pe planul XY (de obicei WorkPlanes.Item(3))
    Dim oXYPlane As WorkPlane = oCompDef.WorkPlanes.Item(3)
    Dim oSketch As PlanarSketch = oCompDef.Sketches.Add(oXYPlane)
    oSketch.Name = "SketchLitere"
    oSketch.Edit()

    ' Selectează fișierul DXF/DWG
    Dim dlg As New System.Windows.Forms.OpenFileDialog()
    dlg.Filter = "DXF or DWG files (*.dxf;*.dwg)|*.dxf;*.dwg"
    dlg.Title = "Selectează fișierul DXF/DWG"
    If dlg.ShowDialog() <> System.Windows.Forms.DialogResult.OK Then
        MessageBox.Show("Fișierul nu a fost selectat.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
        oSketch.ExitEdit()
        Return
    End If

    Dim sFileName As String = dlg.FileName

    ' Lansează comanda de import DXF în schița activă (SketchLitere)
    Dim oCmdMgr As CommandManager = ThisApplication.CommandManager
    oCmdMgr.PostPrivateEvent(PrivateEventTypeEnum.kFileNameEvent, sFileName)
    oCmdMgr.ControlDefinitions("SketchInsertAutoCADFileCmd").Execute()

    ' Așteaptă ca utilizatorul să finalizeze importul în fereastra care s-a deschis
    MessageBox.Show("Finalizează importul în fereastra care s-a deschis, apoi apasă OK aici pentru a continua.", _
                    "Continuă", MessageBoxButtons.OK, MessageBoxIcon.Information)

    ' Închide schița pentru a putea folosi profilele
    oSketch.ExitEdit()

    ' Verifică parametrul "Adancime"
    Dim adancime As Double
    Try
        Dim oParam As UserParameter = oCompDef.Parameters.UserParameters.Item("Adancime")
        adancime = oParam.Value
    Catch ex As Exception
        MessageBox.Show("Parametrul 'Adancime' nu există. Creează-l înainte de a rula regula.", "Eroare", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return
    End Try

    ' Verifică dacă există profile
    If oSketch.Profiles.Count = 0 Then
		
        MessageBox.Show("Nu s-au importat profile din DXF.", oSketch.SketchEntities.Type.ToString, MessageBoxButtons.OK, MessageBoxIcon.Error)
        Return
    End If
    
    ' Extrudare combinată cu toate profilele
    ExtrudeAllProfiles(oCompDef, oSketch, adancime)

End Sub

Sub ExtrudeAllProfiles(oCompDef As PartComponentDefinition, oSketch As PlanarSketch, ByVal adancime As Double)
    ' Crează profil combinat cu găuri din toate profilele schiței
    Dim combinedProfile As Profile = oSketch.Profiles.AddForSolid()

    Dim extrudeDef As ExtrudeDefinition = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(combinedProfile, PartFeatureOperationEnum.kNewBodyOperation)
    extrudeDef.SetDistanceExtent(adancime, PartFeatureExtentDirectionEnum.kPositiveExtentDirection)

    oCompDef.Features.ExtrudeFeatures.Add(extrudeDef)

    MessageBox.Show("Extrudare finalizată cu succes!", "Succes", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
0 Likes
130 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

You were almost there. Profiles are not created automatically. You need to tell Inventor to create the profiles (just before you check if there are any profiles ;-). That is done by adding the following snippet:

oSketch.Profiles.AddForSolid()

 

If your import settings are wrong, then this will fail. By default end endpoints of lines are not constrained. Inventor will therefore assume that the sketch is not a closed loop and will not be able to create a profile. Therefore, you need to make sure your import settings are set correctly. This is the most important setting.

JelteDeJong_0-1753879995041.png

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 3 of 3

mecanicu
Advocate
Advocate

i call-ed : 

 Dim combinedProfile As Profile = oSketch.Profiles.AddForSolid()

in  Sub ExtrudeAllProfiles subroutine

 

Regardin endpoint's I have try this code that u mention in a post : https://forums.autodesk.com/t5/inventor-programming-ilogic/inserting-acad-dfx-into-sketch-of-a-part-...

but whit no success!

0 Likes