Problem with redefine surface

Problem with redefine surface

rikard.nilsson
Collaborator Collaborator
1,217 Views
19 Replies
Message 1 of 20

Problem with redefine surface

rikard.nilsson
Collaborator
Collaborator

Hi,

 

I have an assembly where I try with iLogic to redefine a surface.

But I get an error message that says that "it's not implemented yet" on my Redefine-row..

 

Does anyboby have an idea what I'm doing wrong?

 

Regards

Rikard

 

 

Dim oAssemblyDoc As AssemblyDocument = ThisApplication.ActiveDocument

    Dim oAssemblyDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition

    Dim oOccurrence1 As ComponentOccurrence = Component.InventorComponent("CopyObject2_1")
    Dim oPartDef1 As PartComponentDefinition= oOccurrence1.Definition

    Dim oOccurrence2 As ComponentOccurrence = Component.InventorComponent("CopyObject1")
    Dim oPartDef2 As PartComponentDefinition = oOccurrence2.Definition


    Dim oSourceBody As SurfaceBody = oPartDef1.Worksurfaces.Item(1).Surfacebodies(1)


    Dim oSourceBodyProxy As SurfaceBodyProxy
    oOccurrence1.CreateGeometryProxy(oSourceBody, oSourceBodyProxy)


    Dim oCollection As ObjectCollection= ThisServer.TransientObjects.CreateObjectCollection
    oCollection.Add(oSourceBodyProxy)

    
    Dim nonPrmFeatures As NonParametricBaseFeatures = oPartDef2.Features.NonParametricBaseFeatures 
    Dim nonprmFea As NonParametricBaseFeature = nonPrmFeatures.Item(1)

    nonprmFea.Redefine(oCollection)


    oAssemblyDoc.Update

 

0 Likes
Accepted solutions (1)
1,218 Views
19 Replies
Replies (19)
Message 2 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

A little modification in the code. Please find the modified code in the following.

 

    Dim oAssemblyDoc As AssemblyDocument = ThisApplication.ActiveDocument

    Dim oAssemblyDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition

    Dim oOccurrence1 As ComponentOccurrence = Component.InventorComponent("CopyObject2_1")
    Dim oPartDef1 As PartComponentDefinition= oOccurrence1.Definition

    Dim oOccurrence2 As ComponentOccurrence = Component.InventorComponent("CopyObject1")
    Dim oPartDef2 As PartComponentDefinition = oOccurrence2.Definition


    Dim oSourceBody As SurfaceBody = oPartDef1.Worksurfaces.Item(1).Surfacebodies(1)

	Dim nonPrmFeatures As NonParametricBaseFeatures = oPartDef2.Features.NonParametricBaseFeatures 
	Dim nonprmFea As NonParametricBaseFeature = nonPrmFeatures.Item(1)

	nonprmFea.Redefine(oSourceBody)


    oAssemblyDoc.Update

Please feel free to contact if there is any doubt.


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 3 of 20

rikard.nilsson
Collaborator
Collaborator

Thank you so much!!

 

I did not read the help right.. I read it like there was a need for ObjectCollection instead of an object..  🙂

 

But how do I solve this if I would like to have more than one surfacebody?

 

What I'm really trying to do is to create a function that does the same thing as Refefine in Inventor. Where you can choose more than one body, but without the picking of bodies..

Do you have some idea how to do that aswell?

 

Regards

Rikard

0 Likes
Message 4 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

Please try the following sample code if surface body is more than one.

 

 

    Dim oAssemblyDoc As AssemblyDocument = ThisApplication.ActiveDocument

    Dim oAssemblyDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition

    Dim oOccurrence1 As ComponentOccurrence = Component.InventorComponent("CopyObject2_1")
    Dim oPartDef1 As PartComponentDefinition= oOccurrence1.Definition

    Dim oOccurrence2 As ComponentOccurrence = Component.InventorComponent("CopyObject1")
    Dim oPartDef2 As PartComponentDefinition = oOccurrence2.Definition

    Dim oOccurrence3 As ComponentOccurrence = Component.InventorComponent("CopyObject2_2")
    Dim oPartDef3 As PartComponentDefinition= oOccurrence3.Definition
    
    Dim oSourceBody As SurfaceBody = oPartDef1.Worksurfaces.Item(1).Surfacebodies(1)
    Dim oSourceBody1 As SurfaceBody = oPartDef3.Worksurfaces.Item(1).Surfacebodies(1)

    Dim nonPrmFeatures As NonParametricBaseFeatures = oPartDef2.Features.NonParametricBaseFeatures 
    Dim nonprmFea As NonParametricBaseFeature = nonPrmFeatures.Item(1)

    nonprmFea.Redefine(oSourceBody)
    nonprmFea.Redefine(oSourceBody1)

    oAssemblyDoc.Update

 Please feel free to contact if there is any doubt.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 5 of 20

rikard.nilsson
Collaborator
Collaborator

Hi again,

 

The code you added will not create what I want..

That is just like redefine 2 times and it will only show the last one..

 

Any other idea?

 

/Rikard

0 Likes
Message 6 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

Please explain with example what you are looking for?

 

If there is any image that will be better.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 7 of 20

rikard.nilsson
Collaborator
Collaborator

Hi,

 

I wrote this in an earlier post..

"What I'm really trying to do is to create a function that does the same thing as Redefine in Inventor. Where you can choose more than one body, but without the picking of bodies.."

 

And as you can see in redefine2.jpg it will still be one surface and create the scuplt in both places..

 

I hope this explains it a little better..

 

/Rikard

 

 

0 Likes
Message 8 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support
Accepted solution

Hi Rikard,

 

Please find the following sample code to copy 2 part bodies to another part.

 

    Dim oAssemblyDoc As AssemblyDocument = ThisApplication.ActiveDocument

    Dim oAssemblyDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition

    Dim oOccurrence1 As ComponentOccurrence = Component.InventorComponent("CopyObject2_1")
Dim oPartDef1 As PartComponentDefinition = oOccurrence1.Definition Dim oOccurrence2 As ComponentOccurrence = Component.InventorComponent("CopyObject1") Dim oPartDef2 As PartComponentDefinition = oOccurrence2.Definition Dim oOccurrence3 As ComponentOccurrence = Component.InventorComponent("CopyObject2_2") Dim oPartDef3 As PartComponentDefinition = oOccurrence3.Definition Dim oSourceBody As SurfaceBody = oPartDef1.Worksurfaces.Item(1).Surfacebodies(1) Dim oSourceBody1 As SurfaceBody = oPartDef3.Worksurfaces.Item(1).Surfacebodies(1) Dim oMatrix1 As Matrix oMatrix1 = oOccurrence1.Transformation Dim oMatrix3 As Matrix oMatrix3 = oOccurrence3.Transformation Dim oMatrix2 As Matrix oMatrix2 = oOccurrence2.Transformation oMatrix2.PreMultiplyBy(oMatrix1) Call oPartDef2.Features.NonParametricBaseFeatures.Add(oSourceBody, oMatrix2) oMatrix2 = Nothing oMatrix2 = oOccurrence2.Transformation oMatrix2.PreMultiplyBy(oMatrix3) Call oPartDef2.Features.NonParametricBaseFeatures.Add(oSourceBody1, oMatrix2) oAssemblyDoc.Update

Please feel free to contact if there is any doubt.

 

If solves your problem Accept as Solution / give a Kudo.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 9 of 20

rikard.nilsson
Collaborator
Collaborator

Hi again,

 

I'm so happy that you are helping me,,

And now we are close to get what I want.

 

The code you posted is like Copy Object and I think I can create a sculpt from these new surfaces..

 

But what I'm really would like to do is using Redefine with more than one surface..

Maybe that is not possible..

 

/Rikard

0 Likes
Message 10 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

Yes, you are right. In Redefine method, only one parameter is passed. It defines sculpt but, unable to position it. If there is one more parameter to accept matrix. It might be possible.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 11 of 20

rikard.nilsson
Collaborator
Collaborator

Hi Chandra!

 

 

I've done som more testing with this..

And I think it's time foe me to leave the idea to solve this with Redefine.

 

My new idea is to create the Sculpt by programming. I have found that the Sculpt is more robust to use if the surfaces are Stitched together..

 

My problem now is that I can't create my Knitfeature

 

Dim oStitch As KnitFeature = oPartDef2.Features.KnitFeatures.Add(oSurfaceToStitch)

 

Once again I'm having problem what kind of surface to add to the feature..

 

Do you have a code how to create a stitch of these surfaces that we created before?

 

Regards

Rikard

0 Likes
Message 12 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

Please find a sample code to stitch a component.

 

	Public Sub StitchFeatureCreate()
        ' Create a new part document, using the default part template.
        Dim oPartDoc As PartDocument
        oPartDoc = mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject,
                mApp.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject))

        ' Set a reference to the component definition.
        Dim oCompDef As PartComponentDefinition
        oCompDef = oPartDoc.ComponentDefinition

        ' Create a new sketch on the X-Y work plane. Dim oSketch As PlanarSketch
        Dim oSketch As PlanarSketch
        oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes(3))

        ' Set a reference to the transient geometry object.
        Dim oTransGeom As TransientGeometry
        oTransGeom = mApp.TransientGeometry

        ' Draw two sketch lines that will be used as the
        ' open profiles for creating work surfaces.
        Dim oLineOne As SketchLine
        oLineOne = oSketch.SketchLines.AddByTwoPoints(
                                oTransGeom.CreatePoint2d(0, 0),
                                oTransGeom.CreatePoint2d(2, -2))

        Dim oLineTwo As SketchLine
        oLineTwo = oSketch.SketchLines.AddByTwoPoints(
                                oTransGeom.CreatePoint2d(0, 0),
                                oTransGeom.CreatePoint2d(-2, -2))

        ' Create a profile for the first extrude.
        Dim oProfileOne As Profile
        oProfileOne = oSketch.Profiles.AddForSurface(oLineOne)

        ' Create an surface extrusion 2 cm thick.
        Dim oExtrudeDef As ExtrudeDefinition
        oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfileOne, PartFeatureOperationEnum.kSurfaceOperation)
        Call oExtrudeDef.SetDistanceExtent(2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)
        Dim oExtrudeOne As ExtrudeFeature
        oExtrudeOne = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

        ' Create a profile for the second extrude.
        Dim oProfileTwo As Profile
        oProfileTwo = oSketch.Profiles.AddForSurface(oLineTwo)

        ' Create an extrusion 2 cm thick.
        oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfileTwo, PartFeatureOperationEnum.kSurfaceOperation)
        Call oExtrudeDef.SetDistanceExtent(2, PartFeatureExtentDirectionEnum.kNegativeExtentDirection)
        Dim oExtrudeTwo As ExtrudeFeature
        oExtrudeTwo = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef)

        Dim oSurfaces As ObjectCollection
        oSurfaces = mApp.TransientObjects.CreateObjectCollection

        ' Since we know that the only work surfaces in the document
        ' are those created by the above extrusions, use those.
        oSurfaces.Add(oCompDef.WorkSurfaces.Item(1))
        oSurfaces.Add(oCompDef.WorkSurfaces.Item(2))

        ' Create a stitch (knit) feature by stitching
        ' together the two work surfaces created above.
        Dim oKnitFeature As KnitFeature
        oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)
    End Sub

 

In order to add a knitfeature, "Add" method requires object collection of surfaces. But in attached sample assembly, surfaces are solidbody surfaces. It fails to stitch the surfaces.

 

Manually, I tried to stitch surfaces on main part(CopyObject1). unable to select either of (CopyObject2_1) or (CopyObject2_2).

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 13 of 20

rikard.nilsson
Collaborator
Collaborator

Hi,

 

Thanks again.

I think you missunderstod what I wanted.

As you can see in my added picture you will find that I wanted to stich the two surfaces that you helped me to create in previous posts.

 

And doing that manually works OK.. But I can't find how to add these two to my collection for creating my Stitched Surface.. 

 

/Rikard

0 Likes
Message 14 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

 

 

Sorry for late reply,

 

Can you please send sample part? which is trying to stitch. let me try.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 15 of 20

rikard.nilsson
Collaborator
Collaborator
Hi,

I will try to add one tomorrow.
But you help me earlier to copy two surfaces to one part. And it's those two surfaces I'm trying to stitch.
If you have your old code saved you can use that part to try to stitch them

/Rikard
0 Likes
Message 16 of 20

rikard.nilsson
Collaborator
Collaborator

Hi,

 

Here is a file to test with Stitch

 

/Rikard

0 Likes
Message 17 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

Please send the sample as shown in image stitch.jpg.

 

Stitch feature can be added in a PartDocument. It is not possible to do in AssemblyDocument.

 

I will work on the sample and get back to you.

 

Thanks and regards,

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 18 of 20

rikard.nilsson
Collaborator
Collaborator

Hi,

 

The ipt that I posted before is the same as in the picture..

 

/Rikard

0 Likes
Message 19 of 20

chandra.shekar.g
Autodesk Support
Autodesk Support

Hi Rikard,

 

Thanks for the sample.

 

Please find the sample code to stitch surfaces at component occurrence level.

 

    Dim oAssemblyDoc As AssemblyDocument = ThisApplication.ActiveDocument

    Dim oAssemblyDef As AssemblyComponentDefinition = oAssemblyDoc.ComponentDefinition

    Dim occ As ComponentOccurrence
    occ = oAssemblyDef.Occurrences.ItemByName("CopyObject1")

    occ.Edit()

    Dim oCompDef As PartComponentDefinition
    oCompDef = occ.Definition

    Dim oSurfaces As ObjectCollection
    oSurfaces = ThisApplication.TransientObjects.CreateObjectCollection

    oSurfaces.Add(oCompDef.WorkSurfaces.Item(1))
    oSurfaces.Add(oCompDef.WorkSurfaces.Item(2))

    Dim oKnitFeature As KnitFeature
    oKnitFeature = oCompDef.Features.KnitFeatures.Add(oSurfaces)

    occ.ExitEdit(ExitTypeEnum.kExitToPrevious)
	
    oAssemblyDoc.Update

Before_stitch.JPG

 

 

After_stitch.JPG

Please feel free to contact if there is any doubt.

 


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 20 of 20

rikard.nilsson
Collaborator
Collaborator

Hi again,

 

I have tested this.. And the code is very simular to what I tried with before..

And when I tested it again I still got an error message..

 

But the problem was that I tested it in 2015 and not 2017. So after testing the code in 2017 it works as it should..

 

Thanks for helping me with this.

I thik I will solve the rest in 2017 without any more problems..

 

/Rikard

0 Likes