Hallo Ralf,
ne das gibt es leider so nicht als Standard hinterlegt.
Wobei es meiner Ansicht nach möglich sein sollte. Ähnlich wie bei den Auto Positionsnummern.
Zitat:
Die dürfte schon in Punkt 1 scheitern. Die BrowserNodes im Modellbrowser der Zeichnung liefern meines Wissens nur ein "Generic Object" zurück.
Das könnte man aber eventuell umgehen, indem man in der Ansicht selbst ein Bauteil anwählt und schaut, ob man die ComponentOccurrence bekommt.
das habe ich schon gelöst.
Jetzt macht der Start von der Führungslinie Probleme ich bekomme es nicht hin den Mittelpunkt der Bauteile als Startpunkt der Führungslinie zu definieren.
Das Manuelle nachbearbeiten wäre nicht das Problem.
Das Problem ist die Punkte Kugeln R=50mm im Maßstab 1:50 bei ca 200000 Teilen zu finden (manuell), darum wollte ich es Automatisieren bei ca 2000 Punkten auf 28 Zeichnungen, und für die Zukunft da es eine wiederkehrende Aufgabe sein wird.
Wenn der Text einmal dran ist kann also die Sortierung und Ausrichtung manuell erfolgen.
Was ich bisher habe ....
Ansicht auswählen
Code holt sich die Hauptbaugruppe
das Iprop wird abgefragt
ich kann über Nummern bis zur gewünschten Baugruppe navigieren und dann die Führungslinien Erstellung anstossen, wenn ich in der richtigen Baugruppe angekommen bin.
der Code erstellt auch die Führungslinie aber der Start stimmt nicht.
hier der Ilogic Code, den ich bisher mithilfe vom Internet und Sonnet 4.6 erstellt habe.
Sub Main()
Dim oDrw As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDrw.ActiveSheet
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
'-----------------------------------------------------------
' 1. Ansicht auswählen
'-----------------------------------------------------------
Dim oView As DrawingView
Try
oView = ThisApplication.CommandManager.Pick( _
SelectionFilterEnum.kDrawingViewFilter, _
"Bitte Ansicht auswählen.")
Catch
MsgBox("Keine Ansicht ausgewählt.")
Exit Sub
End Try
'-----------------------------------------------------------
' 2. Hauptbaugruppe aus Ansicht holen
'-----------------------------------------------------------
Dim asmDoc As AssemblyDocument
Try
asmDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument
Catch
MsgBox("Ansicht verweist nicht auf eine Baugruppe.")
Exit Sub
End Try
'-----------------------------------------------------------
' 3. iProperty abfragen
'-----------------------------------------------------------
Dim propName As String = InputBox( _
"Benutzerdefiniertes iProperty eingeben:", "iProperty", "LP")
If propName = "" Then Exit Sub
'-----------------------------------------------------------
' 4. Navigation durch Ebenen
'-----------------------------------------------------------
Dim currentOccs As ComponentOccurrences = asmDoc.ComponentDefinition.Occurrences
Dim selectedOcc As ComponentOccurrence = Nothing
Dim ebene As Integer = 1
Dim transformChain As New List(Of Matrix)
Do While True
Dim nameList As New List(Of String)
Dim occList As New List(Of ComponentOccurrence)
For Each occ As ComponentOccurrence In currentOccs
Try
If occ.DefinitionDocumentType = kAssemblyDocumentObject Then
nameList.Add(System.IO.Path.GetFileName( _
occ.Definition.Document.FullDocumentName))
occList.Add(occ)
End If
Catch
End Try
Next
Dim msg As String = "Ebene " & ebene.ToString & _
" — Unterbaugruppe wählen:" & vbCrLf & vbCrLf
For i = 0 To nameList.Count - 1
msg &= (i + 1).ToString & ": " & nameList(i) & vbCrLf
Next
Dim createOption As Integer = nameList.Count + 1
msg &= vbCrLf & createOption.ToString & ": ► Führungslinientext erstellen"
Dim input As String = InputBox(msg, "Navigation Ebene " & ebene.ToString, "1")
Dim idx As Integer
If Not Integer.TryParse(input, idx) Then Exit Sub
If idx = createOption Then
If selectedOcc Is Nothing Then
MsgBox("Bitte zuerst eine Unterbaugruppe auswählen!")
Continue Do
End If
Dim count As Integer = 0
Dim errors As Integer = 0
Dim combinedMatrix As Matrix = GetCombinedMatrix(transformChain, oTG)
ProcessAllParts(selectedOcc.SubOccurrences, combinedMatrix, _
oView, oSheet, oTG, propName, count, errors)
MsgBox("Fertig!" & vbCrLf & _
"Führungslinien erstellt: " & count & vbCrLf & _
"Fehler / iProperty fehlt: " & errors)
Exit Sub
End If
idx -= 1
If idx < 0 Or idx >= occList.Count Then
MsgBox("Ungültige Eingabe.")
Continue Do
End If
selectedOcc = occList(idx)
transformChain.Add(selectedOcc.Transformation)
currentOccs = selectedOcc.SubOccurrences
ebene += 1
Loop
End Sub
'-----------------------------------------------------------
' Kombinierte Matrix berechnen
'-----------------------------------------------------------
Function GetCombinedMatrix(chain As List(Of Matrix), oTG As TransientGeometry) As Matrix
Dim result As Matrix = oTG.CreateMatrix()
result.SetToIdentity()
For Each m As Matrix In chain
result.PreMultiplyBy(m)
Next
Return result
End Function
'-----------------------------------------------------------
' Rekursiv alle Bauteile beschriften
'-----------------------------------------------------------
Sub ProcessAllParts( _
occs As ComponentOccurrences, _
parentMatrix As Matrix, _
oView As DrawingView, _
oSheet As Sheet, _
oTG As TransientGeometry, _
propName As String, _
ByRef count As Integer, _
ByRef errors As Integer)
Dim oOcc As ComponentOccurrence
For Each oOcc In occs
If oOcc.DefinitionDocumentType = kPartDocumentObject Then
Dim worldMatrix As Matrix = parentMatrix.Copy()
worldMatrix.PreMultiplyBy(oOcc.Transformation)
SetLeader(oOcc, worldMatrix, oView, oSheet, oTG, propName, count, errors)
ElseIf oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then
Dim subMatrix As Matrix = parentMatrix.Copy()
subMatrix.PreMultiplyBy(oOcc.Transformation)
ProcessAllParts(oOcc.SubOccurrences, subMatrix, oView, oSheet, _
oTG, propName, count, errors)
End If
Next
End Sub
'-----------------------------------------------------------
' Führungslinie setzen
' Ankerpunkt = Ursprung (0,0,0) des Bauteils → Weltkoordinaten → Zeichnung
'-----------------------------------------------------------
Sub SetLeader( _
occ As ComponentOccurrence, _
worldMatrix As Matrix, _
oView As DrawingView, _
oSheet As Sheet, _
oTG As TransientGeometry, _
propName As String, _
ByRef count As Integer, _
ByRef errors As Integer)
' iProperty lesen
Dim val As String = ""
Try
val = occ.Definition.Document.PropertySets( _
"Inventor User Defined Properties")(propName).Value
Catch
Try
val = occ.Definition.Document.PropertySets( _
"Design Tracking Properties")(propName).Value
Catch
errors += 1
Exit Sub
End Try
End Try
If val = "" Then
errors += 1
Exit Sub
End If
Try
' === Ursprung (0,0,0) des Bauteils in Weltkoordinaten transformieren ===
' worldMatrix enthält bereits die vollständige Transformationskette
' Der Ursprung des Bauteils ist (0,0,0) im lokalen System
Dim oOrigin As Point = oTG.CreatePoint(0, 0, 0)
oOrigin.TransformBy(worldMatrix)
' worldMatrix gibt Werte in cm zurück (Inventor intern = cm)
' oView.Position ist in cm
' oView.Scale ist dimensionslos
' === Kameraparameter für Projektion ===
Dim cam As Camera = oView.Camera
Dim upVec As UnitVector = cam.UpVector
Dim viewDir As UnitVector = cam.Eye.VectorTo(cam.Target).AsUnitVector()
Dim rightVec As Vector = upVec.AsVector().CrossProduct(viewDir.AsVector())
' === Relative Position: Ursprung - Kameraziel ===
' cam.Target ist in cm, oOrigin ist in cm → direkt subtrahieren
Dim relX As Double = oOrigin.X - cam.Target.X
Dim relY As Double = oOrigin.Y - cam.Target.Y
Dim relZ As Double = oOrigin.Z - cam.Target.Z
Dim relVec As Vector = oTG.CreateVector(relX, relY, relZ)
' === Projektion auf Zeichenebene × Maßstab ===
Dim projX As Double = relVec.DotProduct(rightVec) * oView.Scale
Dim projY As Double = relVec.DotProduct(upVec.AsVector()) * oView.Scale
' === Ankerpunkt auf Blatt (cm) ===
Dim anchorX As Double = oView.Position.X + projX
Dim anchorY As Double = oView.Position.Y + projY
' === Textpunkt rechts neben der Ansicht, gleiche Höhe ===
Dim textX As Double = oView.Position.X + (oView.Width / 2) + 2.0
Dim textY As Double = anchorY
' === Führungslinie erstellen ===
Dim oPts As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection()
oPts.Add(oTG.CreatePoint2d(anchorX, anchorY))
oPts.Add(oTG.CreatePoint2d(textX, textY))
oSheet.DrawingNotes.LeaderNotes.Add(oPts, val)
count += 1
Catch ex As Exception
errors += 1
End Try
End Sub
------------------
- - - der Erleuchtung ist es egal wie du Sie erlangst - - -
- - - Wir leben alle unter demselben Himmel, aber wir haben nicht alle denselben Horizont - - - (K. Adenauer)
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP