Create line at angle?

Create line at angle?

mslosar
Advisor Advisor
4,025 Views
3 Replies
Message 1 of 4

Create line at angle?

mslosar
Advisor
Advisor

Can this be done?

 

Im trying to create a plate flange (think donut shape with a pattern of holes through it).

 

The holes typically need to straddle the normal centerlines (0 and 90 degree). In Inventor, i'd build this by laying out the donut shape and extruding it. Then doing a new sketch off the top of that. In that sketch, i'd draw a circle that is the center of the holes and draw a line from the center point straight up to 90 degrees on the circle. I'd then draw a line at an angle to the edge of the circle and place a point at that end. I'd finish by placing an angle dimension between the lines and setting it to the angle i desire, like 15 degrees). At that point, exit the sketch, create a hole and pattern it.

 

I'm having trouble figuring out how to use vb  to creat that line at an angle. The only thing I can think of is running the math to figure out the X, Y coordinates of the 15 degree line and drawing an addbytwopoints line from 0,0 to the calculated coordinates. Is that the only way?

0 Likes
4,026 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni

You did a great job of explaining the problem until I got to "I'd then draw a line at an angle to the edge of the circle and place a point at that end."  Can you attach a picture of what you're trying to accomplish?  I'm guessing that it should be possible to do the same thing through the API that you're doing interactively but as you said, you also have the option of calculating the end points of the line.  It mainly depends on if you need some kind of associative relationship between the line and the circle so that if geometry is updated the line will update correctly.  If you just calculate it's position it's correct when you first create it but without having those relationships between the line and other geometry it won't update if the model is changed.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 3 of 4

mslosar
Advisor
Advisor
Actually, it's at the office and i'm home for the weekend, so i can't do anything til monday on the picture front. I'll try the text version from that point. After having a constrained vertical line.... -I create a second line, from 0,0 to the edge of the circle, roughly 30ish degrees to the right (about 1 oclock on a clock). -After that I throught a dimension constraint on it to set to whatever angle i choose - 15 degrees for the sake of argument. -That locks the lines in position. -At that point, i create a point (sketch/point) at the end of the second line. -that point is used in the hole command -Finish sketch -hole command using the point just created. I actually got it functioning about 5 minutes before i left the office today 🙂 I'll post what I came up with monday when I get in. My guess is you can do much better than I did 🙂 The whole procedure is creating a base ring, 2 plate flanges about 12" apart with an array of gussets between them. I'm trying to see if i can do the whole thing via code. Can't quite template an assembly of them since they change every time and need unique filenames and iassemblies don't seem to work because you have to basically pre-determine your options. We were close with 'place an ilogic component', but we can't auto-tag job numbers to the part/assembly files that way. Thanks for the looking and i'll up my duct-tape solution monday!
0 Likes
Message 4 of 4

mslosar
Advisor
Advisor

Ok, a bit late, been swamped this week 🙂

 

Here's what I came up with last week.

 

Public Sub BP()
    ' Create a new part document, using the default part template.
    Dim oPartDoc As PartDocument
    Set oPartDoc = ThisApplication.Documents.Add(kPartDocumentObject, _
                ThisApplication.FileManager.GetTemplateFile(kPartDocumentObject))
                    
    ' Set a reference to the component definition.
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oPartDoc.ComponentDefinition
    
    ' Create a new sketch on the X-Z work plane.  Since it's being created on
    Dim oSketch As PlanarSketch
    Set oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(2))
    
    ' Set a reference to the transient geometry object.
    Dim oTransGeom As TransientGeometry
    Set oTransGeom = ThisApplication.TransientGeometry
    
    'project origin point
    Dim OP As SketchPoint
    Set OP = oSketch.AddByProjectingEntity(oCompDef.WorkPoints.Item(1))
    
    ' Draw a 4cm x 3cm rectangle with the corner at (0,0)
    Dim oc As SketchCircle
    Set oc = oSketch.SketchCircles.AddByCenterRadius(OP, 24 * 2.54)
    'Set oc = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(0, 0), 24 * 2.54)
    
    Dim dimOD As DimensionConstraint
    Set dimOD = oSketch.DimensionConstraints.AddDiameter(oc, oTransGeom.CreatePoint2d(3, 3), False)
    dimOD.Parameter.Name = "OD"
                  
    Dim IC As SketchCircle
    Set IC = oSketch.SketchCircles.AddByCenterRadius(OP, 18 * 2.54)
    'Set IC = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(0, 0), 18 * 2.54)
    
    Dim dimID As DimensionConstraint
    Set dimID = oSketch.DimensionConstraints.AddDiameter(IC, oTransGeom.CreatePoint2d(-5, -5), False)
    dimID.Parameter.Name = "ID"

    'Create a Profile
    Dim Prof As Profile
    Set Prof = oSketch.Profiles.AddForSolid

    'Create solid extrusion
    Dim Ex1 As ExtrudeDefinition
    Set Ex1 = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(Prof, kJoinOperation)
    Call Ex1.SetDistanceExtent(1, kPositiveExtentDirection)
    Dim oExtrude1 As ExtrudeFeature
    Set oExtrude1 = oCompDef.Features.ExtrudeFeatures.Add(Ex1)
    
    'Create new sketch on top face
    Dim TopF As Face
    Set TopF = oExtrude1.EndFaces.Item(1)
    
    Set oSketch = oCompDef.Sketches.AddWithOrientation(TopF, oCompDef.WorkAxes.Item(1), True, True, oCompDef.WorkPoints(1))
    Set OP = oSketch.AddByProjectingEntity(oCompDef.WorkPoints.Item(1))
    
    Dim SL1 As SketchLine
    Set SL1 = oSketch.SketchLines.AddByTwoPoints(OP, oTransGeom.CreatePoint2d(0, 21 * 2.54))
     
    Dim vert As GeometricConstraint
    Set vert = oSketch.GeometricConstraints.AddVertical(SL1)
    
    Dim LL As DimensionConstraint
    Set LL = oSketch.DimensionConstraints.AddTwoPointDistance(SL1.StartSketchPoint, SL1.EndSketchPoint, kAlignedDim, oTransGeom.CreatePoint2d(7, 15), False)
    
    Dim SL2 As SketchLine
    Set SL2 = oSketch.SketchLines.AddByTwoPoints(OP, oTransGeom.CreatePoint2d(15, 30))
    
    Dim L2 As DimensionConstraint
    Set L2 = oSketch.DimensionConstraints.AddTwoPointDistance(SL2.StartSketchPoint, SL2.EndSketchPoint, kAlignedDim, oTransGeom.CreatePoint2d(7, 15), False)
    L2.Parameter.value = 21 * 2.54
    L2.Parameter.Name = "BCD2"
    
    Dim A1 As DimensionConstraint
    Set A1 = oSketch.DimensionConstraints.AddThreePointAngle(SL2.EndSketchPoint, OP, SL1.EndSketchPoint, oTransGeom.CreatePoint2d(15, 15), False)
    A1.Parameter.value = ((180 - 15) * 3.1415) / 180
    A1.Parameter.Name = "Angle1"
    
    oPartDoc.Update
    
    
    ' Create an object collection for the hole center points.
    Dim oHoleCenters As ObjectCollection
    Set oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection
    
    Dim myX, myY As Double
    
    myX = SL2.EndSketchPoint.Geometry.X
    myY = SL2.EndSketchPoint.Geometry.Y
    
    ' Add two points as hole centers.
    'oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(0, 21 * 2.54)) works
    'oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(SL2.EndSketchPoint.HoleCenter))
    'Call oHoleCenters.Add(oSketch.SketchPoints.Add(SL2.EndSketchPoint))
    oHoleCenters.Add oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(myX, myY), True)
       
    ' Create the hole feature.
    Call oCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent( _
                            oHoleCenters, "1 in", kPositiveExtentDirection)
                                
    
    oPartDoc.Update
     
    'fit view
    ThisApplication.ActiveView.Fit
    
         
End Sub
0 Likes