Sketch Offset curves not working

Sketch Offset curves not working

Anonymous
Not applicable
1,627 Views
10 Replies
Message 1 of 11

Sketch Offset curves not working

Anonymous
Not applicable

I am trying to SWEEP a profile and a path. It fails as both are bit apart (not intersecting). So I wish to bring path upto profile. I am trying that by offsetting curves of path, upto point projected from profile.

 

Here is the code:

 

                ' project first point on to path's sketch plane, and then offset the path to that point so that SWEEP's profile and path will intersect
                Dim oStartPointProfile As SketchPoint = oProfiles.Item(1).Item(1).Item(1).StartSketchPoint
                Dim wpt As WorkPoint = oCompDef.WorkPoints.AddFixed(oStartPointProfile.Geometry3d, True)

                ' Get path's sketch
                Dim pathSketch As PlanarSketch = path.Item(1).SketchEntity.Parent

                ' Make a new sketch by copying evrything from path sketch
                Dim newPathSketch As PlanarSketch = CreateNewSketch(pathSketch, True)

                ' Get a point to offset the path to
                Dim newProjectedPoint As SketchPoint = newPathSketch.AddByProjectingEntity(wpt)

                Dim oCollection As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection
                oCollection.Add(newPathSketch.SketchLines.Item(1)) ' Is SketchEntities better than SketchLines, hmm. crashes!!

                Dim offsettedentities As SketchEntitiesEnumerator = newPathSketch.OffsetSketchEntitiesUsingPoint(oCollection, newProjectedPoint.Geometry, True, False)

                Dim newPath As Inventor.Path = oCompDef.Features.CreatePath(offsettedentities.Item(1))

Offsetting does not work. It appears that one line has got offsetted but others did not follow. I do not want two copies, but just one offsetted closed loop path.

 

SketchOffsetCurvesProblem.png

 

 

0 Likes
Accepted solutions (1)
1,628 Views
10 Replies
Replies (10)
Message 2 of 11

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

If you offset the curves then you are making the area bigger. Is that what you want?

 

If the path is correct, the profile is correct, the origin point is not set for the sketches (i.e. they will use the origin of the part) and you just need to align them then you would need to make sure that both curves go through the origin  - just like in case of the part document you attached (or did you attach the wrong ipt file?)

 

You could just move the entities in the sketch of your choice based on that, so that the curve will go through the origin of the sketch. 

 

Setting the origin point of one of the sketches so that they will line up might also be an option - depending on the exact situation.

 

Could you attach the ipt where the sweep fails?

 

Cheers,

 

 

 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 3 of 11

Anonymous
Not applicable

After implementing the suggestion you had given for mismatching Sketch Origins, elsewhere, path offset still does not work.

Attached please find the part at problem state. Following picture shows the same state:

 

 

 

SweepPathDoesNotIntersect.png

 

But Interactively this works:

 

 

SweepPathDoesNotIntersectButInteractiveWorks.png

 

Surprisingly, in inteactive mode, it did not complain that path is not intersecting the profile!! Do not know why, but it does sometimes. Anyway, both the SWEEP APIs still do not work.

 

 

                Dim oSweepOne As SweepFeature = Nothing

                For Each oProfileOne In oProfiles
                    Try
                       oSweepOne = oCompDef.Features.SweepFeatures.AddUsingPath(oProfileOne, newPath, PartFeatureOperationEnum.kSurfaceOperation, SweepProfileOrientationEnum.kNormalToPath)
                    Catch ex2 As Exception
                        Try
                            oSweepOne = oCompDef.Features.SweepFeatures.AddUsingPath(oProfileOne, newPath, PartFeatureOperationEnum.kSurfaceOperation, SweepProfileOrientationEnum.kParallelToOriginalProfile)
                        Catch ex As Exception
                            CreateMidurfByOffsettingSweepfaces(sweepFeature, oCompDef.Thickness.Value / 2.0, True)
                        End Try
                    End Try
                Next

Here I have not done Profiles.AddForSurface. Is it mandatory? or just looping the way I have done is OK, considering I am sending kSurFaceOperation?

 

 

 

 

0 Likes
Message 4 of 11

adam.nagy
Autodesk Support
Autodesk Support

I think you rely on the autoselect when creating the sweep in the UI - and so Inventor will choose the closed spline loop (Sketch6) as the profile and the single straight line (Sketch5) as the path. If you do the same in your code then that will work too - see below.

 

If you add another sketch to the part so that Inventor will not do an autoselect and you select the straight line as profile and the spline loop as path, then that will fail in the UI too.

 

I think it would make things easier for you if you did small functions in VBA that concentrated on the issue. It would make things easier for others (inc me 🙂 as well) to test what you say.

 

Something like this, where you just have to select Sketch5 then Sketch6 (both needs to be selected and in this order) then run this code - this should succeed:

Sub CreateSweep()
    Dim doc As PartDocument
    Set doc = ThisApplication.ActiveDocument

    Dim oCompDef As PartComponentDefinition
    Set oCompDef = doc.ComponentDefinition
    
    Dim skPath As PlanarSketch
    Set skPath = doc.SelectSet(1)
    
    Dim skProfile As PlanarSketch
    Set skProfile = doc.SelectSet(2)
    
    Dim oPath As Path
    Set oPath = oCompDef.Features.CreatePath(skPath.SketchLines(1))
  
    Dim oProfile As Profile
    Set oProfile = skProfile.Profiles.AddForSurface()
  
    Dim oSweepone As SweepFeature
    Set oSweepone = oCompDef.Features.SweepFeatures.AddUsingPath( _
        oProfile, oPath, PartFeatureOperationEnum.kSurfaceOperation, _
        SweepProfileOrientationEnum.kNormalToPath)
End Sub

 



Adam Nagy
Autodesk Platform Services
0 Likes
Message 5 of 11

Anonymous
Not applicable

I am seeing similar error with both open profiles as well.

 

Attached please find the project having two parts in "My Project Directory". Zip is encrupted with your first name as password.

 

Please put a breakpoint at GenerateMidsurfaceFromSweep for both the cases. I guess I am passing correct profile and path, but not sure what is failing. Even the exception does not give any info.

 

 

0 Likes
Message 6 of 11

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

Could you please try to narrow down the problem so that it can be reproduced with a sample document and just a small piece of VBA code?

 

Thank you,



Adam Nagy
Autodesk Platform Services
0 Likes
Message 7 of 11

Anonymous
Not applicable

Attached please find a part having two sketches: sketch6 is the PATH sketch and sketch5 is the profile sketch.

 

Interactively, when I supply the verttical line that is not intersecting the path, Surface-Sweep does not work. But when I select intersecting vertical line as profile, then sweep works fine.

 

How to offset Profile to meet Path.png

 

Intent is to

  1. how to detect if path and profile are not intersecting
  2. If so, how to offset/shift profile curves, so that they intersect the path

 

The code I am using is:

 

               ' Need any geom entity of the sketch, for shifting/offsetting later
                Dim newPath As Inventor.Path = Nothing
                Dim anySketchEntity As SketchEntity = Nothing
                If newPathSketch.SketchLines.Count > 0 Then
                    anySketchEntity = newPathSketch.SketchLines.Item(1) ' Is SketchEntities better than SketchLines, hmm. crashes!!
                ElseIf newPathSketch.SketchArcs.Count > 0 Then
                    anySketchEntity = newPathSketch.SketchArcs.Item(1) ' SO PATHETIC logic, just becuase sketchentities crashes
                Else
                    anySketchEntity = newPathSketch.SketchPoints.Item(1)
                End If

                ' Profile and Path should intersect, but generally they are away. [ BUT, HOW TO CHECK IF THEY ARE INTERSECTING???]
                ' So, project first point on to path's sketch plane, and then offset the path to that point so that SWEEP's profile and path will intersect
                Dim oStartPointProfile As SketchPoint = oProfiles.Item(1).Item(1).Item(1).StartSketchPoint
                Dim wpt As WorkPoint = oCompDef.WorkPoints.AddFixed(oStartPointProfile.Geometry3d, True)
                Dim whenOffsetStartsWorking As Boolean = False
                ' Get a point to offset the path to
                Dim newProjectedPoint As SketchPoint = newPathSketch.AddByProjectingEntity(wpt)
                Dim oCollection As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection
                oCollection.Add(anySketchEntity)
                Dim offsettedentities As SketchEntitiesEnumerator = newPathSketch.OffsetSketchEntitiesUsingPoint(oCollection, newProjectedPoint.Geometry, True, False)
                newPath = oCompDef.Features.CreatePath(offsettedentities.Item(1))

Dim oProfileOne As Profile
                oProfileOne = newProfileSketch.Profiles.AddForSurface(newProfileSketch.SketchLines.Item(1))
                oSweepOne = oCompDef.Features.SweepFeatures.AddUsingPath(oProfileOne, newPath, PartFeatureOperationEnum.kSurfaceOperation, SweepProfileOrientationEnum.kNormalToPath)

Any suggestions?

 

 

0 Likes
Message 8 of 11

adam.nagy
Autodesk Support
Autodesk Support

Is there a reason why you keep trying to use the single line as the profile and the spline as the path?

At the end of the day you'll get the same result as using the single line as path and the spline as profile, and then you don't have to move things around.



Adam Nagy
Autodesk Platform Services
0 Likes
Message 9 of 11

Anonymous
Not applicable

Yes. This implementation is part of an academic research where I am trying to create a mid-surface of a Sweep feature. Procedure is to get mid-curve of the Sweeps profile and then sweep it using its path. Mid-curve is computed for a generic profile and can be branched. For simple shapes, like rectangle, mid-curve comes as a straight line. I can not change the shape of path, may be just shift/offset it. So what goes in as Profile and as Path is kind-of fixed.

0 Likes
Message 10 of 11

adam.nagy
Autodesk Support
Autodesk Support
Accepted solution

OK.

Just so that you would not have to do transformations, you could simply do this:

1) make sure that the profile sketch is before the path sketch in the browser tree (because of next point)

2) project the bottom most sketch point in the profile sketch into the path sketch

3) offset the path sketch spline to the projected skecth point - see below code

 

In the attached file the only thing I modified is the order of the two sketches and I projected the profile's bottom left sketch point into the path sketch

 

You can just open this file and run this code to get the offset path:

Sub OffsetPathToLastSketchPoint()
  ' We got the last sketch point from
  ' projecting the base point of the line in the
  ' profile sketch (Sketch5) into the path sketch (Sketch6)
  Dim d As PartDocument
  Set d = ThisApplication.ActiveDocument
  
  Dim cd As PartComponentDefinition
  Set cd = d.ComponentDefinition
  
  Dim s As PlanarSketch
  Set s = cd.Sketches("Sketch6")
  
  Dim p As SketchPoint
  Set p = s.SketchPoints(s.SketchPoints.Count)
  
  Dim l As SketchControlPointSpline
  Set l = s.SketchControlPointSplines(1)
  
  Dim t As TransientObjects
  Set t = ThisApplication.TransientObjects
  
  Dim c As ObjectCollection
  Set c = t.CreateObjectCollection
  
  Call c.Add(l)
  
  Dim se As SketchEntitiesEnumerator
  Set se = s.OffsetSketchEntitiesUsingPoint(c, p.Geometry)
End Sub

 



Adam Nagy
Autodesk Platform Services
Message 11 of 11

Anonymous
Not applicable

It Worked!!...Thanks for your help.

 

Following is the code I have now. I had to do some hardcoding, for now, but will tackle the inflexibility later. For now, this case works ok.

 

                Dim profileSketch As PlanarSketch = profile.Parent
                Dim newProfileSketch As PlanarSketch = m_Utilities.CreateNewSketch(profileSketch) ' Creating EMPTY sketch, so NOT copying the contents. IT HAS TO BE BEFORE PATH SKETCH
                Dim oProfiles As ObjectCollection = GenerateNewProfilesFromMidcurves(newProfileSketch, midcurves)

                ' Copy of original path as Path Sketch
                Dim pathSketch As PlanarSketch = path.Item(1).SketchEntity.Parent
                Dim newPathSketch As PlanarSketch = m_Utilities.CreateNewSketch(pathSketch, True) ' Copy contents from original path to new path sketch

                Dim oStartPointProfile As SketchPoint = oProfiles.Item(1).Item(1).Item(1).StartSketchPoint
                Dim wpt As WorkPoint = oCompDef.WorkPoints.AddFixed(oStartPointProfile.Geometry3d, True)
                Dim newProjectedPoint As SketchPoint = newPathSketch.AddByProjectingEntity(wpt)

                ' TBD: Need a check if newProjectedPoint is already on any of the sektch geometry entity, if so, do not need to OFFSET as below, at all
                'Dim interSketch As Sketch3D = oCompDef.Sketches3D.Add
                'Dim intcurves As IntersectionCurves = interSketch.IntersectionCurves.Add(newProfileSketch.SketchLines.Item(1), newPathSketch.SketchLines.Item(1))

                Dim oCollection As ObjectCollection = _invApp.TransientObjects.CreateObjectCollection

                ' DOES NOT WORK if I add all the SketchEntities to this collection. 
                ' I need some other generic container having only sketch geometry entities and 
                ' which does not have entities like dimensions constraints etc
                For Each ske As SketchLine In newPathSketch.SketchLines ' HARDCODED, TBD
                    oCollection.Add(ske)
                Next
                Dim se As SketchEntitiesEnumerator = newPathSketch.OffsetSketchEntitiesUsingPoint(oCollection, newProjectedPoint.Geometry)
                Dim newPath As Inventor.Path = oCompDef.Features.CreatePath(se.Item(1))
                Dim oProfileOne As Profile = newProfileSketch.Profiles.AddForSurface(newProfileSketch.SketchLines.Item(1))
                Dim oSweepOne As SweepFeature = Nothing
                Try
                    oSweepOne = oCompDef.Features.SweepFeatures.AddUsingPath(oProfileOne, newPath, PartFeatureOperationEnum.kSurfaceOperation, SweepProfileOrientationEnum.kNormalToPath)
                Catch ex As Exception
                    CreateMidurfByOffsettingSweepfaces(sweepFeature, smallestProfileSidelength / 2.0, True)
                End Try

 

Offset Profile meets Path.png

 

Thanks a lot.

 

0 Likes