Message 1 of 4
VBA Make a Hexagone
Not applicable
07-07-2018
12:05 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi, and thanks for reading!
Private Function buildPoligone(oparamD) As SketchBlock
Dim SelectedPoint As Inventor.SketchPoint
Set SelectedPoint = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchPointFilter, "Select the point...")
ThisApplication.CommandManager.StopActiveCommand
' Connect to a running instance of Inventor.
Dim invApp As Inventor.Application
Set invApp = ThisApplication
'System.Runtime.InteropServices.Marshal.GetActiveObject
'("Inventor.Application")
' Set a reference to the active sketch.
Dim oSketch As PlanarSketch
Set oSketch = ThisApplication.ActiveEditObject
' Get a reference to the TransientGeometry object.
Dim tg As Inventor.TransientGeometry
Set tg = invApp.TransientGeometry
' Get a reference to the SketchLines collection.
Dim olines As Inventor.SketchLines
Set olines = oSketch.SketchLines
' Get a reference to the SketchCircle collection.
Dim oCircles As Inventor.SketchCircles
Set oCircles = oSketch.SketchCircles
Dim oCircle1 As Inventor.SketchCircle
Set oCircle1 = oCircles.AddByCenterRadius(SelectedPoint, oparamD)
oparamRi = oparamRi / 2
oparamRc = oparamRi / (Math.Sqr(3) / 2)
Dim oInscribedPoint As Inventor.SketchPoint
Set oInscribedPoint = SelectedPoint
oInscribedPoint.Geometry.X = SelectedPoint.Geometry.X - oparamRc
oInscribedPoint.Geometry.Y = SelectedPoint.Geometry.Y
' Define inputs needed to rotate.
Dim col As ObjectCollection
Set col = ThisApplication.TransientObjects.CreateObjectCollection
Call col.Add(oInscribedPoint)
Dim i As Long
Dim rotatePoint As Point2d
Set rotatePoint = tg.CreatePoint2d(0, 0)
rotatePoint.X = SelectedPoint.Geometry.X
rotatePoint.Y = SelectedPoint.Geometry.Y
Dim pi As Double
pi = Atn(1) * 4
Dim Angle As Double
Angle = Me.Angle.Value * (pi / 180)
For i = 1 To 6
Dim colsub As ObjectCollection
Set colsub = ThisApplication.TransientObjects.CreateObjectCollection
colsub.Add (oSketch.RotateSketchObjects(col, rotatePoint, Angle + 60 * (i)))
Next
Dim oline As Inventor.SketchLine
Dim StPoint As Object
Set StPoint = colsub(1)
Dim EnPoint As Object
Set EnPoint = colsub(2)
Set oline = olines.AddByTwoPoints(StPoint, EnPoint)
End FunctionAfter so much pain with this problem, I still can t make a simple hexagone with VBA. Here the object collection (named "subcol") is not filling up (shun't I get 6 object in it?) .
Why does this synthaxe:
colsub.Item(i).Add (oSketch.RotateSketchObjects(col, rotatePoint, Angle + 60 * (i)))
..that seems to be used all over exemples, doesn t work in my case?
Also tryed the methode to make a hexagone directly without any succes...
Dim oline1 As Inventor.SketchLine
Set oline1 = olines.AddByTwoPoints(oInscribedPoint.Geometry.X, SelectedPoint
Dim opoly As Inventor.Polyline2d
Dim oSides As Long
oSides = 6
opoly = olines.AddAsPolygon(6, SelectedPoint, oInscribedPoint, True)Any clues?

