Sketch Redifine by selection.

Sketch Redifine by selection.

shastu
Advisor Advisor
921 Views
14 Replies
Message 1 of 15

Sketch Redifine by selection.

shastu
Advisor
Advisor

I think I just need help with one line.  If I uncomment the one line that is commented it works except it obviously puts the sketch on the YZ workplane.  Instead I want it to put the sketch on the face that I picked.  I tried modifying the line which is below the commented line and I realize that (oFace) is not a valid argument but I think it helps you understand what I am wanting.  See below:

 

Public Sub SketchRedefine()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
    Dim sketch As PlanarSketch
    Set sketch = partDef.Sketches.Item(1)
    Dim oFace As Face
    Set oFace = ThisApplication.CommandManager.pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Select the face")
   
    'sketch.PlanarEntity = partDef.WorkPlanes.Item(1)
    sketch.PlanarEntity = partDef.SurfaceBodies(oFace)
    ThisApplication.ActiveView.Fit
End Sub

0 Likes
922 Views
14 Replies
Replies (14)
Message 2 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @shastu,

 

I think in your example you were trying to redefine the first sketch of the part onto a face of the part (partDef.Sketches.Item(1), but I think you'd need to be sure that the face isn't dependent on the sketch being redefined, meaning we can't redefine a sketch of a square that defines the face of the cube, etc.

 

In any case this example works for me, assuming Sketch2 (or partDef.Sketches.Item(2)  ) is a sketch that has been placed on the face of a cube.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

Public Sub SketchRedefine()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
    Dim sketch As PlanarSketch
    Set sketch = partDef.Sketches.Item("Sketch2")
    Dim oFace As Face
    Set oFace = ThisApplication.CommandManager.pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Select the face")
   
    sketch.PlanarEntity = oFace
    ThisApplication.ActiveView.Fit
End Sub

EESignature

0 Likes
Message 3 of 15

Curtis_Waguespack
Consultant
Consultant

Or maybe this 

 

Public Sub SketchRedefine()
    Dim partDoc As PartDocument
    Set partDoc = ThisApplication.ActiveDocument
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
    Dim sketch As PlanarSketch
    Set sketch = ThisApplication.CommandManager.Pick(Inventor.SelectionFilterEnum.kSketchObjectFilter, "Select the sketch")
    Dim oFace As Face
    Set oFace = ThisApplication.CommandManager.pick(Inventor.SelectionFilterEnum.kPartFaceFilter, "Select the face")
   
    sketch.PlanarEntity = oFace
    ThisApplication.ActiveView.Fit
End Sub
 

EESignature

0 Likes
Message 4 of 15

shastu
Advisor
Advisor

I am still missing something.  When I do it in Inventor, everything is still constrained, but when I use your code it isn't and shifts to the upper corner of the block.  See attachments.

0 Likes
Message 5 of 15

shastu
Advisor
Advisor

This is not a true Redefine, but rather a move.  If I copy the sketch and then create a new sketch on that same face, I get the same results as your code, but I need code for a true redefine to the plane I picked.

0 Likes
Message 6 of 15

Curtis_Waguespack
Consultant
Consultant

@shastu wrote:

This is not a true Redefine, but rather a move.  If I copy the sketch and then create a new sketch on that same face, I get the same results as your code, but I need code for a true redefine to the plane I picked.


Hi @shastu ,

 

I just provided a working example for the line of code you were asking about... it redefines the sketch plane, but it does reset something to do with the location, so it behaves as it it is moving it... I forget how that works at the moment... I'm pretty sure there is an option to hold the origin, etc... but I suspect it doesn't matter

 

I think what you're really after goes back to the previous thread... so with that in mind here is an example using the file you posted named 2018DC.ipt .... this example uses the hole to find the sketch and then it breaks the link to the lines as provided by @JelteDeJong , then it resets the body that the hole cuts through, so it basically "repairs" the errors in the hole feature... (it does leave the sketch underdefined as a result though)

 

Give this a try and see if this isn't in line with what you're after.

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

Sub Main()

    Dim oDoc As PartDocument
    Set oDoc = ThisApplication.ActiveDocument
    Dim oCompDef As PartComponentDefinition
    Set oCompDef = oDoc.ComponentDefinition

    Dim oHole As HoleFeature
    Dim oSketch As Sketch
    
    For Each oHole In oCompDef.Features.HoleFeatures
        If Not oHole.Sketch Is Nothing Then
                    
            Set oSketch = oCompDef.Sketches.Item(oHole.Sketch.Name)
            
            Dim oline As SketchLine
            For Each oline In oSketch.SketchLines
                oline.Reference = False
            Next

            Dim oObjectCollection As ObjectCollection
            Set oObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
            
            Call oObjectCollection.Add(oCompDef.SurfaceBodies.Item(1))
            Call oHole.SetAffectedBodies(oObjectCollection)
        
        oDoc.Update
            
        End If
    Next

End Sub

 

EESignature

0 Likes
Message 7 of 15

shastu
Advisor
Advisor

No, these are two separate scenarios.  That was for holes, this redefine that I am needing now is for extrusions.  I need a way to do the same thing as a right mouse click on an extrusion sketch and then a left mouse click on redefine and then selecting a face that is parallel to the original sketch.

0 Likes
Message 8 of 15

shastu
Advisor
Advisor

By the way,  I understand that you were just giving me what I was asking for.  I just realized after the fact that it wasn't truly what I needed.  Sorry if it seemed as if I was upset or blaming you.

0 Likes
Message 9 of 15

Curtis_Waguespack
Consultant
Consultant

@shastu wrote:

No, these are two separate scenarios.  That was for holes, this redefine that I am needing now is for extrusions.  I need a way to do the same thing as a right mouse click on an extrusion sketch and then a left mouse click on redefine and then selecting a face that is parallel to the original sketch.


Ahhh, Ok... well I'll try to look on Monday, if someone doesn't come along before then.... but I think there is an option to keep the sketch from jumping when redefining it.... 

EESignature

0 Likes
Message 10 of 15

shastu
Advisor
Advisor

O.K.  Have a good weekend.

Message 11 of 15

Curtis_Waguespack
Consultant
Consultant

@shastu wrote:

By the way,  I understand that you were just giving me what I was asking for.  I just realized after the fact that it wasn't truly what I needed.  Sorry if it seemed as if I was upset or blaming you.


no, no... that wasn't it ... .I was just trying to explain ahead of time why I was switching gears on you, and going back to the other model. 

EESignature

0 Likes
Message 12 of 15

shastu
Advisor
Advisor

Curtis,  Did you ever have a chance to look at this some more?  I still have not come up with a solution.

 

Thanks,

Shawn

0 Likes
Message 13 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @shastu ,

 

I looked at this again briefly on Monday, it was clear to me that the center of the sketch was being "moved" from the center to the lower(or upper) corner when we redefined it... I looked through the API for some control to prevent or fix this but didn't find it.... but I'm pretty sure I've dealt with that in the past. 

 

Unfortunately, that's all the further I have on this though.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

EESignature

0 Likes
Message 14 of 15

Curtis_Waguespack
Consultant
Consultant

Hi @shastu 

 

I just had another quick look and noticed the version in post 3 of this thread worked for me, on the test file I just ran it on... that file was just a rectangle extruded to be  block, and then a sketch on one face of that block with another rectangle extruded.... the test file I was using last week was the derived part with a sketch and hole on it's face... in that one the sketch "jumped" to a different location with redefined, in the case just now it did not. 

 

post 3:

https://forums.autodesk.com/t5/inventor-customization/sketch-redifine-by-selection/m-p/9289477#M1052...

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

EESignature

0 Likes
Message 15 of 15

shastu
Advisor
Advisor

I already tried that in post 3 and it still jumps for me.

0 Likes