Cone isExpanding

Cone isExpanding

rolandas_vegis
Advocate Advocate
1,214 Views
8 Replies
Message 1 of 9

Cone isExpanding

rolandas_vegis
Advocate
Advocate

How to find out whether a cone is expanding or not? Cone object doesn’t have that property and there doesn’t seem to be a way to calculate it from existing properties. Inventor Cone object has isExpanding property.

0 Likes
Accepted solutions (1)
1,215 Views
8 Replies
Replies (8)
Message 2 of 9

marshaltu
Autodesk
Autodesk

Hello,

 

There is no expanding property in geometry object "Cone". It would be good if you can explain a little bit about the workflow what you are going to do. We can probably find a workaround for you.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 3 of 9

rolandas_vegis
Advocate
Advocate

Was writing a method to calculate whether a cylinder is interior or exterior. How should I calculate it for cones without the is expanding property?

0 Likes
Message 4 of 9

marshaltu
Autodesk
Autodesk

Hello,

 

I assume there is a context for cylinder or cone. Otherwise it seems that there is no way to calculate that. For the example the snapshot shows. There are two cone surfaces: interior and exterior. We can differentiate it by the normal on parameter point (0.5, 0.5). 

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback

def run(context):
  ui = None
  try:
    app = adsk.core.Application.get()
    ui  = app.userInterface

    face = adsk.fusion.BRepFace.cast(ui.activeSelections.item(0).entity)
    res, normal = face.evaluator.getNormalAtParameter(adsk.core.Point2D.create(0.5, 0.5))

    ui.messageBox('Axis is {}, {}, {}'.format(normal.x, normal.y, normal.z))

  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

Cone.png



Marshal Tu
Fusion Developer
>
0 Likes
Message 5 of 9

marshaltu
Autodesk
Autodesk

I realized the previous solution would not work if there is only one cone surface. The following codes just show how to judge if cone is interior or exterior by the angle between the normal and axis of cone surface. If it is larger than 90 degree, the cone is interior. Otherwise it is exterior.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback
import math

def run(context):
  ui = None
  try:
    app = adsk.core.Application.get()
    ui  = app.userInterface

    face = adsk.fusion.BRepFace.cast(ui.activeSelections.item(0).entity)
    cone = adsk.core.Cone.cast(face.geometry)
    res, normal = face.evaluator.getNormalAtParameter(adsk.core.Point2D.create(0.5, 0.5))
    angle = normal.angleTo(cone.axis) * 180.0 / math.pi

    ui.messageBox('Axis is {}'.format(angle))

  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
0 Likes
Message 6 of 9

VismantasKizelis
Enthusiast
Enthusiast

Hello

It happens that cone axis returned by API does not always match the cone direction. I got a model of two cones pointing differend directions, but API returns Vector3D(0, 0, -1) for both of them. So one cone has angle between axis and normal >90 and other cone has angle <90 degrees, but both are exterior cones.

Cones.png

0 Likes
Message 7 of 9

marshaltu
Autodesk
Autodesk

Hello,

 

It would be good if you share a copy of the design to me. I can take a look then.

 

Thanks,

Marshal



Marshal Tu
Fusion Developer
>
0 Likes
Message 8 of 9

VismantasKizelis
Enthusiast
Enthusiast
0 Likes
Message 9 of 9

marshaltu
Autodesk
Autodesk
Accepted solution

Hello,

 

I changed the codes a little bit. It should work well for your case now. Please give a try.

 

Thanks,

Marshal

 

import adsk.core, adsk.fusion, traceback
import math

def run(context):
  ui = None
  try:
    app = adsk.core.Application.get()
    ui  = app.userInterface

    face = adsk.fusion.BRepFace.cast(ui.activeSelections.item(0).entity)
    cone = adsk.core.Cone.cast(face.geometry)
    origin = cone.origin
    
    res, normal = face.evaluator.getNormalAtParameter(adsk.core.Point2D.create(0.5, 0.5))  
    res2, point = face.evaluator.getPointAtParameter(adsk.core.Point2D.create(0.5, 0.5))
    axis = adsk.core.Vector3D.create(point.x - origin.x, point.y - origin.y, point.z - origin.z)
    angle = normal.angleTo(axis) * 180.0 / math.pi

    ui.messageBox('Angle is {}'.format(angle))

  except:
    if ui:
      ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


Marshal Tu
Fusion Developer
>
0 Likes