API - hole setPositionByPlaneAndOffsets - bug(?)

API - hole setPositionByPlaneAndOffsets - bug(?)

pludikar
Collaborator Collaborator
7,691 Views
40 Replies
Message 1 of 41

API - hole setPositionByPlaneAndOffsets - bug(?)

pludikar
Collaborator
Collaborator

Repost - Apologies - I accidently posted this in the API forum (here)

 

I'm trying to set the location of a hole a fixed distance from 2 sides of a corner, using 

returnValue = holeFeatureInput_var.setPositionByPlaneAndOffsets(planarEntity, point, edgeOne, offsetOne, edgeTwo, offsetTwo) 

 

I can get this to work as expected on an occurrence, but when the Occurrence has either been moved (with position capture) or is located via a join, then the direction of the two offsets appear to be unpredictable.  This results in the hole being placed in the wrong quadrant, but depends on the actual location of the corner.

 

I have definitely placed the initial guess position (point) correctly, and the final hole center should be exactly on the guess point - so the positioning algorithm should resolve to an immediate solution.  I created a sketch and visually confirmed that the location of the initial guess point is where I expected it to be.  Both offsets are the same and positive.  Hole centers on unmoved, and non-joined occurrences are also exactly where I expected them to be - on the sketch point.

 

I suspect this is a bug.  If it isn't, could you provide a code example based on occurrences.

 

Thanks

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
7,692 Views
40 Replies
Replies (40)
Message 21 of 41

pludikar
Collaborator
Collaborator

@marshaltu

 

You might also want to try adding holes using the "to extent" via the normal UI dialog.   I don't know if the model got corrupted, but this happens often and reflects the issues I'm having with the hole creation API.  The 'to extent' seems to lock up and won't allow a face to be selected.

 

 

hole creation example v1.png

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 22 of 41

marshaltu
Autodesk
Autodesk
Hello,

Thank you for detailed information. I will give a try later. I forgot to mention I will take one-week vacation(Chinese New Year) from today on and would have delay response. I hope the issue would not block you.

Thanks,
Marshal


Marshal Tu
Fusion Developer
>
0 Likes
Message 23 of 41

pludikar
Collaborator
Collaborator

@marshaltu

 

No problem.  Enjoy your week off.  Kong he fat choi

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 24 of 41

marshaltu
Autodesk
Autodesk

Hello,

 

I looked into your codes and sample file. It works well now after I do some modification. 

 

    1. If you want to pick up the occurrence "root->build:1->Component1:2", you can use "root.allOccurrences.item(1)" to retrieve it.

    2. The method "face.nativeObject.pointOnFace" should be able to get a point on the face.

    3. "matchShape" argument in setOneSideToExtent cannot be set into "True" in the case. I can see same issue in UI. I am not sure if it is bug or not and will check with our hole feature experts.

 

Thanks,

Marshal

 

 

import adsk.core, adsk.fusion, traceback

def run(context):
  ui = None
  try:
    app = adsk.core.Application.get()
    ui  = app.userInterface
    
    design = adsk.fusion.Design.cast(app.activeProduct)
    root = design.rootComponent
    
    holeFeatures = root.features.holeFeatures
    holeDiam = adsk.core.ValueInput.createByString('10 mm')
    holePosX = adsk.core.ValueInput.createByString('1 mm')
    holePosY = adsk.core.ValueInput.createByString('1 mm')
    tipAngle = adsk.core.ValueInput.createByString('180 deg')
    holeDepth = adsk.core.ValueInput.createByString('30 mm')

    #occ = root.occurrences.item(0)
    #occ = root.occurrences.item(1)
    #embedded = occ
    embedded = root.allOccurrences.item(1)
    body = adsk.fusion.BRepBody.cast(embedded.bRepBodies.item(0))
    face = body.faces.item(0)
    
    #find opposing face
    faceNormal = face.evaluator.getNormalAtPoint(face.pointOnFace)[1]
    oppFace = None

#find opposite side face    
    for face1 in face.body.faces:
        if faceNormal.isPerpendicularTo( face1.evaluator.getNormalAtPoint(face1.pointOnFace)[1]):
            continue
        if face1 == face:
            continue
        oppFace = face1
        break
    holeFeatures = face.body.parentComponent.features.holeFeatures  #surely - to be consistent, shouldn't holes be a feature of the component, not the rootComponent?
        
    pointOnFace = face.nativeObject.pointOnFace
    
    edge1 = face.edges.item(0)
    edge2 = face.edges.item(1)
    
    holeInput = holeFeatures.createSimpleInput(holeDiam)
    holeInput.tipAngle = tipAngle
    holeInput.setPositionByPlaneAndOffsets(face, pointOnFace, edge1, holePosX, edge2, holePosY)
    holeInput.setOneSideToExtent(oppFace, False)
#    holeInput.setDistanceExtent(holeDepth)
    holeInput.creationOccurrence = embedded  #I would expect this to be needed, if not for generic case when?
    
    holeFeatures.add(holeInput)     
    
  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) 

 



Marshal Tu
Fusion Developer
>
0 Likes
Message 25 of 41

marshaltu
Autodesk
Autodesk

Hello,

 

I figure it out. The option "Match Shape" can only work when the projection of whole hole is inside "To" face. Otherwise an modeling error will pop up and says "Cannot create hole toolbody, please check inputs" in UI.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 26 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu,

 

I'm not sure that 'The option "Match Shape" can only work when the projection of whole hole is inside "To" face' is consistent.  When you do the same on components that are not part of an assembly it works.  I can see situation where you have two components in an assembly and you want to make a hole from one component to a face or entity (for example an edge) in the other component where the "to" face is not fully over the hole.  What you are suggesting means that F360 isn't supposed to do that operation.  This feels like a bug to me.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
Message 27 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu

 

It appears that the problem is the 'to' selection is not consistent.  Sometimes it works and sometimes it doesn't.  Using the Hole feature in the UI: if the 'To' method is selected from a previous attempt, it seems to prevent any face from being selected.  I tried creating a screencast, but with the laptop I am presently using I don't have enough screen space to reach the save and upload button.  Is there a short cut key I can use - I don't see one in the help.

 

When the face is refusing to be selected, I need to change the "To" to "distance", then back again to "To".  It then appears to work.

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 28 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu

 

Finally managed to save and upload the screencast.  It illustrates the issues I've been reporting (it's taken a while to capture this)

 

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
Message 29 of 41

marshaltu
Autodesk
Autodesk

Hello,

 

Thank you for detailed steps. FUS-38541 is created to track the issue in our internal system.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 30 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu

 

Thanks for getting this tracked.  Hopefully you can get this resolved quickly - it's a show stopper in what I'm trying to do.  

 

I believe that this might be just a symptom of something deeper in F360.  I tried to create an extrude feature under exactly the same circumstances - this time it fatally crashed F360.  I strongly suspect that this is a related issue.  If nothing else F360 should have thrown an error, and not crash!!

 

Here's the crash report No:  CER_165095196

Description:

 

F360 crashing while attempting use API to extrude in an occurrence

 

Salient code snippet:

 

 

                    lastProfile = sketch.profiles.count-1

                    profile = sketch.profiles.item(lastProfile)
                    
                    extentToEntity = dbUtils.findExtent(face, edge)
                    endExtentDef = adsk.fusion.ToEntityExtentDefinition.create(extentToEntity, False)
                    startExtentDef = adsk.fusion.ProfilePlaneStartDefinition.create()
                    profile = profile.createForAssemblyContext(occ) if face.assemblyContext else profile
                    
                    
                    extrInput = adsk.fusion.ExtrudeFeatureInput.cast(None)
                    extrInput = comp.features.extrudeFeatures.createInput(profile, adsk.fusion.FeatureOperations.CutFeatureOperation)
                    extrInput.creationOccurrence = occ
                    extrInput.participantBodies = [face.body]
                    extrInput.startExtent = startExtentDef
                    extrInput.setOneSideExtent(endExtentDef,adsk.fusion.FeatureOperations.CutFeatureOperation)
                    comp.features.extrudeFeatures.add(extrInput)

 

 
I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 31 of 41

marshaltu
Autodesk
Autodesk

Hello,

 

It would be great if you can provide a runnable sample and test design. So that I can give a try in my side and see what's the root cause. I have no idea what could cause the crash with the code snippet. 

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 32 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu

 

In the attached screencast you can see the issue.  It is borne out in the UI, but in the API the same action causes F360 to crash.  The 1st component I show is the same as the second, but the 1st component is in an assembly context.  It is clear that F360 has difficulty recognising the correct body as doesn't know what to snap to in an assembly context - this IMHO is the same characteristic I'm facing in the API in trying to set an appropriate context described in the issue in this thread. 

 

I put together a running API code for you as well, but I think this probably gives you the same information.

 

Peter

 

 

Screencast will be displayed here after you click Post.

94b98050-f953-4ebe-82d4-f0cbcfdd3e4c

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 33 of 41

marshaltu
Autodesk
Autodesk

Hello,

 

Unfortunately it seemed that the screencast wasn't posted successfully. Please post again. Also I didn't find the running API code as you mentioned in the message post.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 34 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu

Here's the screencast.  Unfortunately, I don't have the code yet - been a busy weekend.  I'll get it posted as soon as I can

 

Peter

 

 

 

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 35 of 41

pludikar
Collaborator
Collaborator

@marshaltu

 

here's the running code.  For some reason it doen't cause F360 to crash, but on the other hand it does not form the extrusion in the embedded component.  If you run the script, you can see both extrusions in the timeline.  If you edit the 2nd extrusion you will see that the action of editing will correctly form the extrusion.

 

import adsk.core, adsk.fusion, traceback

def run(context):
  ui = None
  try:
    app = adsk.core.Application.get()
    ui  = app.userInterface
    
    design = adsk.fusion.Design.cast(app.activeProduct)
    root = design.rootComponent
#Create sketch and circle for component at root level    
    compOcc = root.allOccurrences.item(0)
    compBody = adsk.fusion.BRepBody.cast(compOcc.bRepBodies.item(0))
    compFace = compBody.faces.item(0)
    compVertex = compFace.vertices.item(0)
    compPoint = compVertex.nativeObject.geometry
    
    simpleComp = adsk.fusion.Component.cast(compOcc.component)
    compSketch = simpleComp.sketches.add(compFace, compOcc)
    compSketchPoint = compSketch.modelToSketchSpace(compPoint)
    compCircle = compSketch.sketchCurves.sketchCircles.addByCenterRadius(compSketchPoint, 1.2)
    
#simple component find opposing face
    compFaceNormal = compFace.evaluator.getNormalAtPoint(compFace.pointOnFace)[1]
    compOppFace = None

    for face1 in compFace.body.faces:
        if compFaceNormal.isPerpendicularTo( face1.evaluator.getNormalAtPoint(face1.pointOnFace)[1]):
            continue
        if face1 == compFace:
            continue
        compOppFace = face1
        break
        
#Create sketch and circle for embedded component    
    embOcc = root.allOccurrences.item(1)
    embBody = adsk.fusion.BRepBody.cast(embOcc.bRepBodies.item(0))
    embFace = embBody.faces.item(0)
    embVertex = embFace.vertices.item(2)
    embPoint = embVertex.nativeObject.geometry
    embComp = embOcc.component

    embSketch = embComp.sketches.add(embFace, embOcc)
    embSketch = simpleComp.sketches.add(embFace, embOcc)
    embSketchPoint = embSketch.modelToSketchSpace(embPoint)
    embCircle = embSketch.sketchCurves.sketchCircles.addByCenterRadius(embSketchPoint, .6)
    
    #embedded find opposing face
    embFaceNormal = embFace.evaluator.getNormalAtPoint(embFace.pointOnFace)[1]
    embOppFace = None

    for face1 in embFace.body.faces:
        if embFaceNormal.isPerpendicularTo( face1.evaluator.getNormalAtPoint(face1.pointOnFace)[1]):
            continue
        if face1 == embFace:
            continue
        embOppFace = face1
        break

# extrude circle for component at root level    
    compProfiles = adsk.core.ObjectCollection.create()
    for profile in compSketch.createForAssemblyContext(compOcc).profiles:
        if profile.profileLoops.item(0).profileCurves.count != 3:
            continue
        compProfiles.add(profile)
    
    endExtentDef = adsk.fusion.ToEntityExtentDefinition.create(compOppFace, False)
    startExtentDef = adsk.fusion.ProfilePlaneStartDefinition.create()
    
    extrInput = adsk.fusion.ExtrudeFeatureInput.cast(None)
    extrInput = embComp.features.extrudeFeatures.createInput(compProfiles, adsk.fusion.FeatureOperations.CutFeatureOperation)
    extrInput.creationOccurrence = compOcc
    extrInput.participantBodies = [compFace.body]
    extrInput.startExtent = startExtentDef
    extrInput.setOneSideExtent(endExtentDef,adsk.fusion.FeatureOperations.CutFeatureOperation)
    simpleComp.features.extrudeFeatures.add(extrInput)  
    
# extrude circle for embedded component
    embProfiles = adsk.core.ObjectCollection.create()
    for profile in embSketch.createForAssemblyContext(embOcc).profiles:
        if profile.profileLoops.item(0).profileCurves.count != 3:
            continue
        embProfiles.add(profile)
    
    endExtentDef = adsk.fusion.ToEntityExtentDefinition.create(embOppFace, False)
    startExtentDef = adsk.fusion.ProfilePlaneStartDefinition.create()
    
    extrInput = adsk.fusion.ExtrudeFeatureInput.cast(None)
    extrInput = embComp.features.extrudeFeatures.createInput(embProfiles, adsk.fusion.FeatureOperations.CutFeatureOperation)
    extrInput.creationOccurrence = embOcc
    extrInput.participantBodies = [embFace.body]
    extrInput.startExtent = startExtentDef
    extrInput.setOneSideExtent(endExtentDef,adsk.fusion.FeatureOperations.CutFeatureOperation)
    embComp.features.extrudeFeatures.add(extrInput)  




  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 36 of 41

marshaltu
Autodesk
Autodesk

Hello,

 

Thank you for the codes. I can reproduce the issue you mentioned. It is logged as FUS-38599 in our internal system. A workaround for you would be to comment out the line "extrInput.participantBodies = [embFace.body]" to create the second extrusion.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 37 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu

 

Thanks for looking at this.  Unfortunately the work around only works if you want to extrude through the whole body.  I really need this to extrude to a specified entity.  So, I'll have to wait until you can get this resolved.

 

Interestingly, and I don't know if you noticed - the script creates 3 sketches.  I have no idea where the 2nd sketch comes from.

 

Regards

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 38 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu@jeff.strater

 

Can you tell me if anyone has looked at the 3 bug reports (earlier in this thread) I submitted earlier this year.  It is clear from my issues that any component not at the root component has major issues recognising which component cordinate system it's related to.  I have now experienced this same issue wih components that are MIRRORED (So, components in assemblies and mirrored components both exhibit same bug)

 

The attached screen cast shows how I attempt to select a face to extrude a hole to.  The "distance to" face select machanism does not work until the hole is extruded past the native object to another body and then you can select faces on the original native body.

 

I left the whole screen cast unedited, because it appears that not being able to select a native object causes a system crash - possibly due to an incorrect parameter (I've had several models corrupt:  loading the model is fine, but accessing the parameters causes F360 to crash)

 

All these issues appear to have a common thread - the coordinate system of components created by means than other than plain vanilla ones, is broken.  

 

Could you at least please give me a status update - I would like to know if the issues I reported are being addressed.. I would classify this as a Category 5 bug (based on the hurricane measuring system 🙂  ).  If these bugs, I reported, are still hiding in the trenches - How do I get this raised so someone will attend to them?

 

Issue 1: FUS-38207 

Issue 2: FUS-38541

Issue 3: FUS-38599

Issue 4: - see attached screen cast

 

Can you please get this fixed.  It's a fundamental bug and a show stopper!

 

Regards
Peter

 

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 39 of 41

pludikar
Collaborator
Collaborator

Hi @marshaltu

This screencast better illustrates that the mirrored component does not have the correct coordinate system applied to it.  When selecting distance "all" for hole creation, it does not recognise the selected mirrored component, in spite of being the active component!  The component below the selected mirrored component is there to illustrate that "all" command acts on the orginal component coordinate system not the mirror.

 

I can't believe I am the only one to have found this issue.  If I am, then I think it is safe to say that you can make significant functional changes to the API without it affecting a significant number of users.  Your API is unneccessarily complicated, particularly when you refer to assemblyContext and NativeObject coordinate systems in the same call - you should be consistent.  If you deal with a component in an assemblyContext - everything should be referenced to that assembly context.

 

regards

Peter

 

 

 

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes
Message 40 of 41

pludikar
Collaborator
Collaborator

@marshaltu @keqingsong

 

Hi guys,

 

Any chance of a response!

 

Peter

I'm not an expert, but I know enough to be very, very dangerous.

Life long R&D Engineer (retired after 30+ years in Military Communications, Aerospace Robotics and Transport Automation).
0 Likes