Making sketches using iLogic

Making sketches using iLogic

machiel.veldkamp
Collaborator Collaborator
1,409 Views
5 Replies
Message 1 of 6

Making sketches using iLogic

machiel.veldkamp
Collaborator
Collaborator

Hey everybody. 

I'm thinking. 
I'm making a lot of sketches where I'm just making a sketch with a circel on it. 

Should be possible with iLogic right?

 



This is what I had planned. 

Now. I do have a little experience in programming and even with iLogic but when it comes to forms and windows. Well. 
I could use some help!

Where do I begin?

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
1,410 Views
5 Replies
Replies (5)
Message 2 of 6

machiel.veldkamp
Collaborator
Collaborator

What I have so far:

 

'  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

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

Dim doc = ThisApplication.ActiveDocument

Dim oLijn = ThisApplication.CommandManager.Pick(
	SelectionFilterEnum.kSketchCurveLinearFilter, 
	"Select a line")

Dim oPunt = ThisApplication.CommandManager.Pick(
	SelectionFilterEnum.kSketchDefaultFilter, 
	"Select Point")

' Create a work plane at the end of the 2D sketch.
Dim oWP As WorkPlane
oWP = oCompDef.WorkPlanes.AddByNormalToCurve _
(oLijn, oPunt)

' Create a sketch on the Workplane
oSketch = oCompDef.Sketches.Add(oWP)
oOrigin = oSketch.ModelToSketchSpace(oTG.CreatePoint(0, 0, 0))
oSketch.SketchCircles.AddByCenterRadius(oOrigin, 5)

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 3 of 6

machiel.veldkamp
Collaborator
Collaborator

Alright! 

I think I have it!
I want to complete it with a window that asks what geometry and sizes etc to choose. But for version 0.1 this is alright!


' 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

'  a reference to the transient geometry object.
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
Dim doc = ThisApplication.ActiveDocument
Dim oLijn = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Select a line")
Dim oPunt = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchPointFilter, "Select Point")

' Create a work plane at the end of the 2D sketch.
Dim oWP As WorkPlane
oWP = oCompDef.WorkPlanes.AddByNormalToCurve(oLijn, oPunt)
oWP.Visible() = False
Dim oRadius
oDiameter = InputBox("What is the DIAMETER?", "Prompt user for dimensions", "0 ")
If oDiameter = 0
	oDiameter = 10
End If

oRadius = oDiameter/20

' Create a sketch on the Workplane
oSketch = oCompDef.Sketches.Add(oWP)
oRefpunt = oSketch.AddByProjectingEntity(oPunt)

Dim oSketchCircle As SketchCircle
oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oRefPunt, oRadius)

oSketch.GeometricConstraints.AddCoincident(oRefPunt, oSketchCircle.CenterSketchPoint)
'oSketch.DimensionConstraints.AddDiameter(oSketchCircle.ContainingSketchBlock, 0 )

Dim DimC As DimensionConstraint
	DimC = oSketch.DimensionConstraints.AddDiameter(oSketchCircle, oTG.CreatePoint2d(0, 1), False)

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
0 Likes
Message 4 of 6

machiel.veldkamp
Collaborator
Collaborator

Version 0.2

Lot's of improvements!

 

Public Sub Main()
    oChoose
End Sub

Dim oLine
Dim oPoint
Dim oDiameter As String

Public Sub oChoose()
    
    oPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchPointFilter, "Select Point")
    oLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchCurveLinearFilter, "Select a line")
    oDiameter = InputBox("What is the DIAMETER? NOTE:", "Prompt user for dimensions")
    oDiameter = oDiameter.Replace(".", ",")
    oExecute
End Sub

Public Sub oExecute()
    ' This assumes that it is a part document.
    Dim oPartDoc As PartDocument
        oPartDoc = ThisApplication.ActiveDocument
        
    '  a reference to the transient geometry object.
    Dim oTG As TransientGeometry
        oTG = ThisApplication.TransientGeometry
    
    '  a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
        oCompDef = oPartDoc.ComponentDefinition
    
    ' Create a work plane at the end of the 2D sketch.
    Dim oWP As WorkPlane
        oWP = oCompDef.WorkPlanes.AddByNormalToCurve(oLine, oPoint)
        oWP.Visible() = False
    
    ' Create a sketch on the Workplane
    oSketch = oCompDef.Sketches.Add(oWP)
    
    ' Creates a reference point from oPoint on "0, 0"
    oRefpunt = oSketch.AddByProjectingEntity(oPoint)
    
    oDiameter /= 20R
    
    
    'AddByCenterRadius is in cm!!!
    Dim oSketchCircle As SketchCircle
    oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oRefPunt, oDiameter)
    oSketch.GeometricConstraints.AddCoincident(oRefPunt, oSketchCircle.CenterSketchPoint)
    
    Dim DimC As DimensionConstraint
        DimC = oSketch.DimensionConstraints.AddDiameter(oSketchCircle, oTG.CreatePoint2d(0, 1), False)
        InventorVb.DocumentUpdate()
End Sub

 

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________
Message 5 of 6

RoyWickrama_RWEI
Advisor
Advisor

Interesting!

 

I would like to know what does the following part in the code do:

 

  oDiameter = oDiameter.Replace(".", ",")

 

0 Likes
Message 6 of 6

machiel.veldkamp
Collaborator
Collaborator

If the user enters "10,2" this will convert the input to "10.2"

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.

___________________________