iLogic Sketch Redefine.

iLogic Sketch Redefine.

Anonymous
Not applicable
1,549 Views
14 Replies
Message 1 of 15

iLogic Sketch Redefine.

Anonymous
Not applicable

Hi, 

 

I've tried to use "sketch.redefine" syntax according to steps pre described here:

 

https://knowledge.autodesk.com/support/inventor-products/learn-explore/caas/CloudHelp/cloudhelp/2014...

 

but It doesn't work and I don't know why.

Below the snippet of code I've made:

 

SyntaxEditor Code Snippet

Dim oDoc As PartDocument
oDoc = ThisDoc.Document

Dim oDef As PartComponentDefinition
oDef = oDoc.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oDef.Sketches.Item(1)

Sketch.Redefine(oSketch.Name,"P�aszczyzna XY","Punkt �rodkowy","X",AxisIsX := True,NaturalAxisDirection:= True)

The idea is to check and redefine existing sketch on the XY plane.

 

Thanks in advance for any help. 

 

Tomek

0 Likes
Accepted solutions (2)
1,550 Views
14 Replies
Replies (14)
Message 2 of 15

clutsa
Collaborator
Collaborator
Sketch.Redefine(oSketch.Name,"P�aszczyzna XY","Punkt �rodkowy","X", True, True)

I'm guessing the the last two inputs are optional and only need the boolean value. That's just a guess though.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

0 Likes
Message 3 of 15

dgreatice
Collaborator
Collaborator

hi,

 

did you try to redefine manually? and are sketch still healthy? if no, code will still throw a error.

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 4 of 15

Anonymous
Not applicable

It doesn't throw any error and that is strange. I run the rule and just nothing happens. 

 

I'm not sure If I understood the code well, could anybody let me know how originName and planeName should be defined? Specialy I'm not sure about the originName.

 

Thanks for any help.

Regards

Tomek

0 Likes
Message 5 of 15

dgreatice
Collaborator
Collaborator

can you share you file?

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 6 of 15

Anonymous
Not applicable

Attached You'll find the file with rule within.

 

My idea was to create the rule which will check if first sketch was made on XY Plane and if wasn't to redefine sketch on XY Plane automatically.

 

Tomek

0 Likes
Message 7 of 15

dgreatice
Collaborator
Collaborator

Hi, 

 

try this:

    Dim oApp As Application
    Dim oPD As PartDocument
    Dim oPCD As PartComponentDefinition
    Dim oSkt As Sketch
    Dim oXY As WorkPlane
   
    oApp = ThisApplication
    oPD = oApp.ActiveDocument
    oPCD = oPD.ComponentDefinition
    oXY = oPCD.WorkPlanes.Item("XY Plane")
    oSkt = oPCD.Sketches.Item("Szkic2")
   
    If oSkt.PlanarEntity Is oXY Then
    Else
        oSkt.PlanarEntity = oXY
    End If

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 8 of 15

dgreatice
Collaborator
Collaborator

Update for make you first sketch full constraints

 

    Dim oApp As Application
    Dim oPD As PartDocument
    Dim oPCD As PartComponentDefinition
    Dim oSkt As Sketch
    Dim oXY As WorkPlane
    Dim oCentP As WorkPoint
    Dim oSktPt As SketchPoint
   
    oApp = ThisApplication
    oPD = oApp.ActiveDocument
    oPCD = oPD.ComponentDefinition
    oXY = oPCD.WorkPlanes.Item("XY Plane")
    oCentP = oPCD.WorkPoints.Item(1)
   
    oSkt = oPCD.Sketches.Item("Szkic2")
   
    If Not oSkt.PlanarEntity Is oXY Then
        oSkt.PlanarEntity = oXY
    End If
   
    Set oSktPt = oSkt.SketchPoints.Item(1)
    On Error Resume Next
    Call oSkt.AddByProjectingEntity(oCentP)

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 9 of 15

Anonymous
Not applicable

I've tried both and it still doesn't work. 

0 Likes
Message 10 of 15

dgreatice
Collaborator
Collaborator
Accepted solution

strange,

 

showing some error?

 

my code work well

 

 

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 11 of 15

dgreatice
Collaborator
Collaborator

 

 

 

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 12 of 15

Anonymous
Not applicable

Ok, now I can see the problem. U've used direct vba syntax. I need to adjust the code for direct iLogic syntax. 

 

Is there any simple way to do this? I've tried like this: 

 

SyntaxEditor Code Snippet

 Dim oPD As PartDocument
    Dim oPCD As PartComponentDefinition
    Dim oSkt As Sketch
    Dim oXY As WorkPlane
    Dim oCentP As WorkPoint
    Dim oSktPt As SketchPoint
   
    oPD = ThisApplication.ActiveDocument
    oPCD = oPD.ComponentDefinition
    oXY = oPCD.WorkPlanes.Item("XY Plane")
    oCentP = oPCD.WorkPoints.Item(1)
   
    oSkt = oPCD.Sketches.Item("Szkic2")
   
    If Not oSkt.PlanarEntity Is oXY Then
        oSkt.PlanarEntity = oXY
    End If
   
       oSktPt = oSkt.SketchPoints.Item(1)
    On Error Resume Next
    'Call oSkt.AddByProjectingEntity(oCentP)

but it gives me an error at the end.

I'd like to implement the code into a bigger iLogic rule.

 

Tomek

0 Likes
Message 13 of 15

clutsa
Collaborator
Collaborator
Accepted solution
Dim oPD As PartDocument
    Dim oPCD As PartComponentDefinition
    Dim oSkt As PlanarSketch '<------
    Dim oXY As WorkPlane
    Dim oCentP As WorkPoint
    Dim oSktPt As SketchPoint
   
    oPD = ThisApplication.ActiveDocument
    oPCD = oPD.ComponentDefinition
    oXY = oPCD.WorkPlanes.Item("XY Plane")
	

    oCentP = oPCD.WorkPoints.Item(1)
   
    oSkt = oPCD.Sketches.Item("Szkic2")
   
    If Not oSkt.PlanarEntity Is oXY Then
        oSkt.PlanarEntity = oXY
    End If
   
       oSktPt = oSkt.SketchPoints.Item(1)
    On Error Resume Next
    Call oSkt.AddByProjectingEntity(oCentP)

"PlanarEntity" isn't a member of 'Sketch' but is a member of 'PlanarSketch' which is derived from 'Sketch'.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Message 14 of 15

dgreatice
Collaborator
Collaborator

Hi,

 

I don't know about that. maybe still member of Sketch but Hidden? because when I use VBA local window, it show in tree, but not show in quick suggestion member.

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 15 of 15

amichaudJ6E3R
Contributor
Contributor

Hi, I am trying to achieve something similar but using geometry names?

 

I need to dynamically redefine a sketch because if my user is changing the shape of the part, the face where the sketch is assigned to disappear. Is it possible to assign a name to that face, and a name to the other face I want to use, and redefine a sketch with those names using a condition?

 

I've tried the code above by modifying it to what I thought would work, no success there. Is what I want to achieve completely far-fetched?

 

Thanks

0 Likes