Use iLogic to Create Spheres at Points in a 3D Sketch?

Use iLogic to Create Spheres at Points in a 3D Sketch?

Anonymous
Not applicable
2,074 Views
9 Replies
Message 1 of 10

Use iLogic to Create Spheres at Points in a 3D Sketch?

Anonymous
Not applicable

Hello,

 

I have a 3D sketch that includes multiple points. I would like to run an iLogic rule that automatically generates a sphere of radius r, centered at every point defined the 3D sketch. Any ideas? Note: the points are all pulled from an external excel file that defines the X,Y,Z coordinates of each point. I am able to use the Insert -> Points tool to draw these points in the 3D sketch. I have attached an image of my Inventor window to show the "cloud" of points in the 3D sketch.

 

Many Thanks,

Jonathan

0 Likes
Accepted solutions (1)
2,075 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

Would you want the sphere's to be solid bodies, or surface bodies?  How big would you want them?  What would be their purpose?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

WCrihfield
Mentor
Mentor

Would this work for you?

This iLogic rule assumes the active document is a Part document, so if the points are in an assembly, you would have to modify the code for an assembly.

 

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oRevFeats As RevolveFeatures = oPDef.Features.RevolveFeatures
Dim oSphere As RevolveFeature
Dim o3DSketch As Sketch3D = oPDef.Sketches3D.Item(1)
Dim oPoint As SketchPoint3D
Dim oWPlanes As WorkPlanes = oPDef.WorkPlanes
Dim oOrgPlane As WorkPlane = oWPlanes.Item(3) 'same as "XY Plane" if not renamed
Dim oSketches As PlanarSketches = oPDef.Sketches
Dim oWPlane As WorkPlane
Dim oSketch As PlanarSketch
Dim oCircle As SketchCircle
Dim oAxis As SketchLine
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oSPoint,oEPoint As Point2d
Dim oRadius As Double = CDbl(InputBox("Enter a Radius for the spheres.","RADIUS?",3))
Dim oProfile As Profile
Dim oInt As Integer = 1
For Each oPoint In o3DSketch.SketchPoints3D
	oWPlane = oWPlanes.AddByPlaneAndPoint(oOrgPlane, oPoint)
	oSketch = oSketches.Add(oWPlane, False)
	oSketch.OriginPoint = oPoint
	oCircle = oSketch.SketchCircles.AddByCenterRadius(oPoint, oRadius)
	oSPoint = oTG.CreatePoint2d(-oRadius,0)
	oEPoint = oTG.CreatePoint2d(oRadius,0)
	oAxis = oSketch.SketchLines.AddByTwoPoints(oSPoint,oEPoint)
	oAxis.Centerline = True
	oProfile = oSketch.Profiles.AddForSolid
	oSphere = oRevFeats.AddFull(oProfile, oAxis, PartFeatureOperationEnum.kNewBodyOperation)
	oSphere.Name = "Sphere " & i
	oInt = oInt + 1
Next

 

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE" 👍.

Also, when you have time, please review & vote for these 'Ideas' I'd like to get implemented.

  • Add more capabilities to the 'Customize' dialog box (exe. Add Tab & Add Panel) Click Here
  • Constrain & Dimension Images In Assembly Sketches & Drawing Sketches (TitleBlocks & SketchedSymbols) Click Here
  • Save Section View Status In DesignViewRepresentation (So It Can Be Used In The Drawing) Click Here
  • Add SolidBodies Folder In iLogic Rule Editor Model Tab Click Here
  • Convert All Views To Raster Before Autosave Stores To 'OldVersions' Folder Click Here
  • SetDesignViewRepresentation - Fix limitations for DrawingView of a Part Click Here
  • Create DocumentSubTypeEnum Click Here
  • Add kRevisionTag or kDrawingRevisionTag to ObjectTypeEnum Click Here

Inventor 2020 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 10

Anonymous
Not applicable

Hi WCrihfield,

 

Thanks for the quick reply! To answer your previous questions:

(1) Output as solids (separate bodies or one body - either is fine), not surfaces

(2) I need this code for a part, not an assembly

 

Unfortunately, after running this code as an iLogic rule, I received the following error message:

 

Error.png

 

Any ideas? I really appreciate your help!

 

Many Thanks,

Jonathan

0 Likes
Message 5 of 10

J-Camper
Advisor
Advisor

No reason to get iLogic involved.  You can create a sphere at origin, use a Sketch Driven Pattern of your 3D points, and then remove the initial sphere.  Maybe setup a template file with the initial sphere created that you use for bringing the points in to begin with.

 

I have attached a sample part.

0 Likes
Message 6 of 10

Anonymous
Not applicable

Hi JCamper,

 

That's incredible! This feature is perfect for my needs. Thanks for bringing this to my attention. I am hesitant to accept your reply as a solution though. You did solve my problem, just not using iLogic to generate the spheres, so it doesn't exactly solve the original question. Not sure if that goes against the community guidelines for this forum? Perhaps your can weigh in. Thanks so much for your help.

 

Kind Regards,

JPepper

0 Likes
Message 7 of 10

J-Camper
Advisor
Advisor
Accepted solution

@Anonymous,

 

If you still want to figure out how to do it through iLogic, then don't accept my answer.  Otherwise, you can accept it to show it is not an open issue for you anymore.

 

I'm not read up on all the community guidelines either, but that is what I would do.

0 Likes
Message 8 of 10

Anonymous
Not applicable

In case any one is interested here is an edited version of @WCrihfield solution that works for me. I'm not actually sure why it works, because oTG.CreatePoint2d isn't given coords, so I don't know how it gives the coords of the Point3D to the arc creation

 

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition
Dim oRevFeats As RevolveFeatures = oPDef.Features.RevolveFeatures
Dim oSphere As RevolveFeature
Dim o3DSketch As Sketch3D = oPDef.Sketches3D.Item(1)
Dim oPoint3D As SketchPoint3D
Dim oWPlanes As WorkPlanes = oPDef.WorkPlanes
Dim oOrgPlane As WorkPlane = oWPlanes.Item(3) 'same as "XY Plane" if not renamed
Dim oSketches As PlanarSketches = oPDef.Sketches
Dim oWPlane As WorkPlane
Dim oSketch As PlanarSketch
Dim oCircle As SketchArc
Dim oAxis As SketchLine
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oVector As Vector = oTG.CreateVector(0,1,0)
Dim oSPoint,oEPoint As Point2d
Dim oRadius As Double = (CDbl(InputBox("Enter a Radius for the spheres.", "RADIUS?", 3)))/2.54

Dim oProfile As Profile
Dim oInt As Integer = 1
For Each oPoint3D In o3DSketch.SketchPoints3D
	
	Dim oPointProxy As Point2d = oTG.CreatePoint2d
	
	oWPlane = oWPlanes.AddByPlaneAndPoint(oOrgPlane, oPoint3D)
	oSketch = oSketches.Add(oWPlane, False)
	
	oSPoint = oTG.CreatePoint2d(-oRadius,0)
	oEPoint = oTG.CreatePoint2d(oRadius,0)
	oCircle = oSketch.SketchArcs.AddByCenterStartEndPoint(oPointProxy ,oSPoint,oEPoint)
	oAxis = oSketch.SketchLines.AddByTwoPoints(oSPoint,oEPoint)
	oCircle.EndSketchPoint.Merge(oAxis.EndSketchPoint)
	oCircle.StartSketchPoint.Merge(oAxis.StartSketchPoint)
	oProfile = oSketch.Profiles.AddForSolid
	
	
	oSphere = oRevFeats.AddFull(oProfile, oAxis, PartFeatureOperationEnum.kNewBodyOperation)
	oSphere.Name = "Sphere " & oInt
	oInt = oInt + 1
	
Next

 

0 Likes
Message 9 of 10

WCrihfield
Mentor
Mentor

Yes. I wasn't sure if the origin point of the new sketches would be at the Sketch3D Point's position or a projected point from the model's default origin, so I dabbled with setting the oSketch.OriginPoint, which caused errors.  I later found out, by comparing the X & Y values of the oSketch.OriginPointGeometry to the oPoint.Geometry.X & Y, that the new sketches were indeed using the Point3D's position as the origin point, (within my test environment) without needing to specify it, so all that was unnecessary.

 

I got the idea to simply use a simple complete circle, instead of a half circle, from the Primitives Sphere feature, which just creates a revolved feature.  When you create a sphere that way, it uses a complete circle, then rotates it the full 360 degrees around the center line within the revolve feature, to create the sphere.  I don't normally do it this way. I would normally only create a half circle, but then I don't have any reason to regularly create spheres either.

I would say that the Point2D you created was created at the origin of the active sketch environment at the time of creation, so it just happens to work out, because that was the intent point of the circle (half circle) sketch.  That's also why the start point and end points worked, because they are both referencing the X=0 origin point of the sketch, without needing additional instruction.

 

I didn't see where you used the Vector you created within your code

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 10

Anonymous
Not applicable

Oh, the Vector is left over from trying different methods, it's not necessary.

I think I understand now. Even though, my oProxyPoint is created before the sketch is it still has coords (0,0) so when applied to the sketch it uses the (0,0) point in the sketch, which is where we were basing the sphere from anyway. 

 

I tried to use the full circle, but it just didn't seem to want to use the profile created from it. It was only creating one profile even though there should be two, one for each half.

Now that I think about it, I think it had the same problem as I initially had with using the half circle, being that the centerline wasn't constrained to the circle. So even though the start/end points of the line were numerically equal to points on the circle, it still considered them separate and required to be merged.

0 Likes