Angle dimension to 'virtual' perpendicular

Angle dimension to 'virtual' perpendicular

cadman777
Advisor Advisor
2,637 Views
16 Replies
Message 1 of 17

Angle dimension to 'virtual' perpendicular

cadman777
Advisor
Advisor

Hi iLogic experts,

I'm an iLogic dummy and need some help to 'get me by'.

I need a drawing (idw) rule that'll make a sketch on a drawing view, then draw a hash mark at a vertex that is perpendicular to another line in the view. The reason for this is to give Inventor a function that it lacks out-of-the-box (but should have!) for making angle dimensions on a 'virtual' line (like dimensioning the end of a pipe that's mitered so the chop saw guys can setup their saw angle from 0 deg).

The work-flow would be this:

1. run the rule

2. pick the drawing view

3. pick the line

4. pick the vertex (could be 2 crossing lines, a point, end of a line, etc.).

Result: The rule automatically adds a hash line, starting at the picked vertex, and vectoring perpendicular to the picked line, with a length at a specified distance (found inside the rule - don't want user input for this). The direction of the hash mark with respect to the picked line doesn't matter.

This link should clarify what I'm after.

Incidentally, here's an idea of how bad an iLogic guy I am.

Every time I set out to make a rule, it takes me about a week to get back into 'coding'.

Then it takes me about another 3 weeks to try to figure out how to put stuff together.

And when I finally 'give up', I come in here and they always do it another way, so all my work goes down the toilet.

So at this point in my life, I'm just gonna 'ask the experts' instead of 'reinventing the wheel'.

Sound like a plan?!

So maybe someone has a rule like this already made that they'd like to share?

Either way, many thanks for your help!

 

UPDATE:

Another possibility is a rule that turns on the FG part's StartPlane and EndPlane.

That would be easiest, but it would not be best, b/c many of the parts have end treatments that shorten the member's end away from the Start/EndPlanes.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Accepted solutions (3)
2,638 Views
16 Replies
Replies (16)
Message 2 of 17

Michael.Navara
Advisor
Advisor
Accepted solution

This is a nice task. It is not as easy as it looks and it is a nice idea for separate tool. But you can try following code to test. 

 

Expected inputs are:

1) Pick line for perpendicular "virtual" line definition

2) Pick the second line for dimension creation

3) Expected result

MichaelNavara_0-1698669475704.png

 

 

Sub Main()
    Dim lineSegment1 As DrawingCurveSegment = PickCurve()
    Dim lineSegment2 As DrawingCurveSegment = PickCurve()

    Dim viewSketch As DrawingSketch = GetDrawingSketch(lineSegment1)
    Dim sketchLine As SketchLine = CreateSketchLine(viewSketch, lineSegment1, lineSegment2)
    Dim angularDim As AngularGeneralDimension = CreateDimension(lineSegment2, sketchLine)

End Sub

Private Function GetDrawingSketch(lineSegment1 As DrawingCurveSegment) As DrawingSketch
    Dim drawingView As DrawingView = lineSegment1.Parent.Parent
    Dim sketchName As String = drawingView.Name & "_Dimensions"
    Dim drawingSketch As DrawingSketch
    Try
        drawingSketch = drawingView.Sketches.Item(sketchName)
    Catch
        drawingSketch = drawingView.Sketches.Add()
        drawingSketch.Name = sketchName
    End Try
    Return drawingSketch
End Function

Private Function CreateSketchLine(drawingSketch As DrawingSketch, lineSegment1 As DrawingCurveSegment, lineSegment2 As DrawingCurveSegment) As SketchLine

    Dim l1 As LineSegment2d = lineSegment1.Geometry
    Dim l2 As LineSegment2d = lineSegment2.Geometry

    Dim intersectWithCurve As ObjectsEnumerator = l1.IntersectWithCurve(l2)
    Dim intersectionPointInSheetSpace As Point2d = intersectWithCurve(1)

    Dim intersectionPointInSketchSpace = drawingSketch.SheetToSketchSpace(intersectionPointInSheetSpace)
    Dim l1MidPointInSketchSpace = drawingSketch.SheetToSketchSpace(l1.MidPoint)

    Dim directionOfL1 = intersectionPointInSketchSpace.VectorTo(l1MidPointInSketchSpace)

    Dim z = ThisApplication.TransientGeometry.CreateVector(0, 0, 1)
    Dim directionOfL1As3D = ThisApplication.TransientGeometry.CreateVector(directionOfL1.X, directionOfL1.Y, 0)
    Dim lineDirection3d As Vector = z.CrossProduct(directionOfL1As3D)
    Dim lineDirection2d = ThisApplication.TransientGeometry.CreateVector2d(lineDirection3d.X, lineDirection3d.Y)

    lineDirection2d.Normalize()
    lineDirection2d.ScaleBy(l2.StartPoint.DistanceTo(l2.EndPoint))

    Dim endPoint = intersectionPointInSketchSpace.Copy()
    endPoint.TranslateBy(lineDirection2d)

    drawingSketch.Edit()
    Dim line As SketchLine = drawingSketch.SketchLines.AddByTwoPoints(intersectionPointInSketchSpace, endPoint)
    drawingSketch.ExitEdit()

    Return line
End Function

Private Function CreateDimension(line2 As DrawingCurveSegment, sketchLine As SketchLine) As AngularGeneralDimension
    Dim drawingSheet As Sheet = sketchLine.Parent.Parent.Parent
    Dim drwSketch As DrawingSketch = sketchLine.Parent
    Dim textVector = line2.Parent.MidPoint.VectorTo(drwSketch.SketchToSheetSpace(sketchLine.EndSketchPoint.Geometry))
    textVector.ScaleBy(0.5)
    Dim textOrigin As Point2d = line2.Parent.MidPoint 
    textOrigin.TranslateBy(textVector)

    Dim sheet As Sheet = line2.Parent.Parent.Parent
    Dim intent1 As GeometryIntent = sheet.CreateGeometryIntent(line2.Parent)
    Dim intent2 As GeometryIntent = sheet.CreateGeometryIntent(sketchLine)

    Dim angularGeneralDimension As AngularGeneralDimension = drawingSheet.DrawingDimensions.GeneralDimensions.AddAngular(textOrigin, intent1, intent2)
    Return angularGeneralDimension
End Function

Private Function PickCurve() As DrawingCurveSegment
    Return ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingCurveSegmentFilter, "Pick curve")
End Function

 

Message 3 of 17

cadman777
Advisor
Advisor

Hi Michael,

Thanks for creating this rule for me!

I really appreciate your kindness!

I'm running Inventor 2010, and it errors with:

Public member 'Pick' on type 'CommandManager not found.

Any idea why it says that?

I tried finding PickCurves() in the VBA Browser (F2) but couldn't find it.

Is it possible I don't have all the ReferenceLibraries loaded?

These are loaded:

Visual Basic For Applications

Autodesk Inventor Object Library

OLE Automation

There are many more in the list not 'checked'.

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 4 of 17

WCrihfield
Mentor
Mentor
Accepted solution

Hi @cadman777.  The CommandManager.Pick method was introduced in 2011 version, so that will not be usable in 2010 version unfortunately.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 17

cadman777
Advisor
Advisor

Thanks for that info.

No wonder I couldn't find it in my VBA Browser.

I guess I'm becoming outdated! 😋

 

@Michael.Navara

Thanks again for your work!

I gave you a 'Solution' so others can find this tool.

(Although I can't verify it myself and see if it has any 'bugs' that need attention.)

 

Any chance there's a simple way to get the StartPlane and EndPlane to become visible in Inventor 2010 using iLogic?

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 6 of 17

WCrihfield
Mentor
Mentor

I just dropped in to point out that one little detail.  There are other ways to enable manual selection while an iLogic rule is running, but the other ways require a lot more code and complication, which is why that method has had a HUGE impact on iLogic rule functionality ever since it became available.  I know Michael knows all about the alternate selection techniques though, so if needed, I'm sure he would be able to develop an alternate custom Function to the custom PickCurve function he provided in his solution above.  I am not that familiar with FrameGenerator related parts, because I rarely use that tool, but it does sound possible to me.  If the model has those WorkPlanes already, and those planes are perpendicular to the view (so you would see it as a line from the side), then it should be possible with the DrawingView.SetIncludeStatus method, which was made available in 2008.  To use that, you would have to get a reference to the WorkPlane object within the model, then supply that as input into the method.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 17

cadman777
Advisor
Advisor

Thanks Wesley.

I was hoping the work plane 'work-around' was much easier than this one.

Maybe it is?

I spent about 4 hours yesterday looking at web sites that might give me a clue how to make this rule, but it became painfully obvious that it's way over my head. Michael's rule proves that. Anyway, you guys are very kind and generous with your help! 

Incidentally, I appreciate the links you send.

I read them all!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 8 of 17

Michael.Navara
Advisor
Advisor

Here is updated version of previous rule without Pick function. I use TaskCompletionSource as described in this thread

This version uses Async-Await selection in separate thread but it is little bit harder to read.

I hope it will work in Inventor 2010.

 

Message 9 of 17

cadman777
Advisor
Advisor

Thanks for doing this 'challenge' (I read some of your other posts).

Unfortunately, it errored-out with a long list of errors.

But I don't have time to look at it today, so let me get back to you very soon.

I try not to envy you guys in here!

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 10 of 17

cadman777
Advisor
Advisor

I got a chance to look at this today.

Here is the error on the 2 tabs in the DB:

cadman777_0-1698864660467.png

cadman777_1-1698864677306.png

It errors-out as soon as I run it.

IF it's too much trouble, maybe it would be simpler and easier to make a rule that turns-on the Start & End Planes for a FG part? 

Thanks again for your help!

 

... Chris
Win 7 Pro 64 bit + IV 2010 Suite
ASUS X79 Deluxe
Intel i7 3820 4.4 O/C
64 Gig ADATA RAM
Nvidia Quadro M5000 8 Gig
3d Connexion Space Navigator
0 Likes
Message 11 of 17

CCarreiras
Mentor
Mentor

HI!

 

Very nice rule, very handy to use as an external rule.
@Michael.Navara , nice work, thank you!


There's only a detail missing to be 100% perfect:

If the part changes, the drawing will update and the created perpendicular line will be out of place, and then, we have to edit the sketch and attach the line to the intersection point.
Could it be possible the rule create the constrain between the perpendicular line and the picked lines intersection point?

CCarreiras

EESignature

Message 12 of 17

Michael.Navara
Advisor
Advisor
Accepted solution

Good point @CCarreiras. You can easily fix it with geometrical constrains creation. You need just to create new method  and use them, after the sketch line was created. (Near line 50 in original code sample)

 

 

 

Private Function CreateSketchLine(drawingSketch As DrawingSketch, lineSegment1 As DrawingCurveSegment, lineSegment2 As DrawingCurveSegment) As SketchLine
    ...
    drawingSketch.Edit()
    Dim line As SketchLine = drawingSketch.SketchLines.AddByTwoPoints(intersectionPointInSketchSpace, endPoint)
    CreateGeometricalConstraints(lineSegment1, lineSegment2, line)
    drawingSketch.ExitEdit()

    Return line
End Function

Sub CreateGeometricalConstraints(lineSegment1 As DrawingCurveSegment, lineSegment2 As DrawingCurveSegment, line As SketchLine)
    Dim sketch As Sketch = line.Parent
    Dim projectedLineSegment1 = sketch.AddByProjectingEntity(lineSegment1.Parent)
    Dim projectedLineSegment2 = sketch.AddByProjectingEntity(lineSegment2.Parent)
    sketch.GeometricConstraints.AddCoincident(line.StartSketchPoint, projectedLineSegment1)
    sketch.GeometricConstraints.AddCoincident(line.StartSketchPoint, projectedLineSegment2)
    sketch.GeometricConstraints.AddPerpendicular(line, projectedLineSegment1)
End Sub

 

 

 

 

Message 13 of 17

CCarreiras
Mentor
Mentor

WELL DONNE @Michael.Navara !!!

 

NOW IS PERFECT!!!

 

CCarreiras

EESignature

0 Likes
Message 14 of 17

kacper.suchomski
Mentor
Mentor

This is brilliant. Big hugs. 👏

I'm testing this rule right now and I'm wondering about 2 things:

  1. Sometimes the smaller dimension (e.g. 30) is shown first, and sometimes the larger one (e.g. 120) which needs to be moved accordingly. What does it depend on? What do I need to pay attention to?
  2. I also wonder if there is a way to keep the rule active until I press Esc. Right now I have the form in the graphics area so I have the rule close to the mouse when creating many of these dimensions.

Kacper Suchomski

EESignature


YouTube - Inventor tutorials | LinkedIn | Instagram

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


0 Likes
Message 15 of 17

mmckee
Participant
Participant

Michael,

 

is there a way to have this set the reference lines it creates to "sketch only"?

0 Likes
Message 16 of 17

Michael.Navara
Advisor
Advisor

While you are in sketch edit mode, you can set SketchLine.SketchOnly to true.

It is similar to CreateGeometricalConstraints post.

0 Likes
Message 17 of 17

mmckee
Participant
Participant

where would I place this line of code?

0 Likes