Check for sketch availability. ilogic

Check for sketch availability. ilogic

Rogov_Sergey
Collaborator Collaborator
897 Views
2 Replies
Message 1 of 3

Check for sketch availability. ilogic

Rogov_Sergey
Collaborator
Collaborator

Hi, I have an ilogic rule that creates a sweep. But there is a problem when it is executed several times, a bunch of sketches are created. How to do a test I would check if a sketch was created and would give an error if there is one.

 

' a reference to the currently active document.
' This assumes that it is a part document.
Dim oPartDoc As PartDocument
oPartDoc = ThisApplication.ActiveDocument

' a reference to the component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oPartDoc.ComponentDefinition

Dim oPartDef As PartComponentDefinition
oPartDef = oPartDoc.ComponentDefinition

'a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry

'Create a sketch containing a circle.
oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes("Плоскость XY"))
oSketch.Name = "Профиль трубы"
oOrigin = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), ((D_/10)/2))
oOrigin2 = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), ((Dy / 10) / 2))

	
'Create a profile.
Dim oProfile As Profile
oProfile = oSketch.Profiles.AddForSolid

Dim oSketch2 As Sketch3D = oCompDef.Sketches3D.Item("3D эскиз1")
Dim oPath As Path = oCompDef.Features.CreatePath(oSketch2.SketchLines3D(1))

' Create the sweep feature.
Dim oSweep As SweepFeature
oSweep = oCompDef.Features.SweepFeatures.AddUsingPath _
(oProfile, oPath, kJoinOperation)


Находите сообщения полезными? Поставьте Нравится (Like) этим сообщениям!
На ваш вопрос успешно ответили? Нажмите кнопку 'Утвердить решение'


Рогов Сергей/ Rogov Sergey
Инженер-конструктор

0 Likes
Accepted solutions (1)
898 Views
2 Replies
Replies (2)
Message 2 of 3

WCrihfield
Mentor
Mentor
Accepted solution

Try this.  I added a couple checks in there to help catch errors.  It checks to see if that first named PlanarSketch exists or not.  And is also checks to see if the Sketch3D exists or not.  Since you didn't name your SweepFeature yet, I didn't include a check to see if it exists yet.

The oExists As Boolean is a clasic method I use a lot, to ckeck if something "Exists" or not. 🙂

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
For Each oSketchCheck As PlanarSketch In oPDef.Sketches
	If oSketchCheck.Name = "Профиль трубы" Then
		MsgBox("A sketch named " & oSketchCheck.Name & " already exists.")
		Return
	End If
Next
Dim oSketch As PlanarSketch = oPDef.Sketches.Add(oPDef.WorkPlanes("Плоскость XY"))
oSketch.Name = "Профиль трубы"
Dim oOrigin As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), ((D_/10)/2))
Dim oOrigin2 As SketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(0, 0), ((Dy / 10) / 2))
Dim oProfile As Profile = oSketch.Profiles.AddForSolid

Dim oExists As Boolean = False
For Each o3DSketch As Sketch3D In oPDef.Sketches3D
	If o3DSketch.Name = "3D эскиз1" Then
		oExists = True
	End If
Next
If oExists = False Then
	MsgBox("Can't find 3D Sketch named '3D эскиз1'")
	Return
End If

Dim oSketch2 As Sketch3D = oPDef.Sketches3D.Item("3D эскиз1")
Dim oPath As Path = oPDef.Features.CreatePath(oSketch2.SketchLines3D(1))
Dim oSweep As SweepFeature = oPDef.Features.SweepFeatures.AddUsingPath(oProfile, oPath, kJoinOperation)
'oSweep.Name = 

If this solves your problem or answers you questions, please click 'Accept As Solution'.

Or if this helps you along the way to reach your goal, please click 'Likes' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 3

Rogov_Sergey
Collaborator
Collaborator

Thank you very much you've been very helpful.



Находите сообщения полезными? Поставьте Нравится (Like) этим сообщениям!
На ваш вопрос успешно ответили? Нажмите кнопку 'Утвердить решение'


Рогов Сергей/ Rogov Sergey
Инженер-конструктор

0 Likes