Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Questions about iLogic and Sketches

11 REPLIES 11
Reply
Message 1 of 12
mk92
603 Views, 11 Replies

Questions about iLogic and Sketches

Hello,

 

i have a few general questions about iLogic and Inventor.

 

1. Every line or radius i draw gets some parameters, but does inventor now to which line they belong? So is there a designation for each line or radius in the sketch?

 

2. If yes, can i work with them? Like Line_1 is 2000mm long and starts at x/y/z. Or Radius_1 has a radius 1000mm and is 90deg. Starts at...

 

3. How can i say with iLogic "Put Workingpoint "Start" from Part XY connected to Point XY in the Assembly?

 

The task is to draw a sketch with lines and radii and let Inventor place parts on these. Like a chain which has different parts in the straight and curved parts of it. The extended task is to have different parts in different radii.

 

Regards

11 REPLIES 11
Message 2 of 12
RodrigoEiras
in reply to: mk92

 

Hi,

 

I suggest you to start with the Programming/API help in Inventor. You will find detailed information about how sketches work.

 

APihelpssketches.JPG

 

It's a good starting point.

 

Best regards

 

 

Message 3 of 12
mk92
in reply to: RodrigoEiras

So i have read it. I found this:

 

Dim oCoord1 As Point2d
Set oCoord1 = oTransGeom.CreatePoint2d(0, 0)
Dim oCoord2 As Point2d
Set oCoord2 = oTransGeom.CreatePoint2d(5, 0)
 
Dim oLines(1 To 4) As SketchLine
Set oLines(1) = oSketch.SketchLines.AddByTwoPoints(oCoord1, oCoord2)

 

This creates a line between two points in a sketch.

 

But i need it the other way around. The user creates a line and i have to work with the line parameters.

Message 4 of 12
RodrigoEiras
in reply to: mk92

 

Then it is much easier.

 

Each dimension you use to size your sketch is automatically given a parameter name and added to the parameter tab.

 

parameters.JPG

 

In your iLogic rule you can set the value of the parameters to the value you want just writing:

 

   d0 = <new d0 value>

   d1 = < new d1 value>

 

 

Best regards

 

 

Tags (2)
Message 5 of 12
mk92
in reply to: RodrigoEiras

I know. But thats not enought. It makes no difference between a Arc and a Line.

 

The parameters in need are:

What is it? Arc or Line?

StartPoint (XYZ)

EndPoint(XYZ)

If Arc, Radius?

 

I need to place components on the first line from StartPoint to the EndPoint. And other Parts from Arc StartPoint to Arc EntPoint.

 

Pic

Message 6 of 12
LukeDavenport
in reply to: mk92

 

Hi mk92. 

I don't think anyones going to write all your code for you. Generally you'll need to refer to the API help and other forum articles, get some code together and then if you can't get it to work, post it on the forum for assistance.

 

The article below isn't exactly what you want, but the iLogic code shows looping through the first sketch in the active part, and accesses the length property of each sketch entity (SketchLine, SketchArc, SketchCircle objects etc.) using SketchLine.Length for instance. Each of these objects also has an EndPoint and a StartPoint property, in addition to many others, which should get you towards your end goal.

 

https://www.cadlinecommunity.co.uk/hc/en-us/articles/201896032-Inventor-2014-iLogic-Optimize-Loop-Le...

 

Good luck

Luke

Message 7 of 12
mk92
in reply to: LukeDavenport

Thanks a lot! Thats the hint i needed.

 

I dont want anyone to write it for me!!! By no means.

 

 

Message 8 of 12
LukeDavenport
in reply to: mk92

 

You're welcome. Mark my response as the solution to help others find it. And giving people kudos is always a nice way to thank them for donating their time.

Message 9 of 12
mk92
in reply to: LukeDavenport

I have come forward but i need help with an error. The lenght of each SketchLine is shown correctly, but the ForEach for the Start and End Points causes an error. "Object variable or With block variable not set" Any help?

 

 

Dim oSketch As PlanarSketch
oSketch = ThisApplication.ActiveEditObject

Dim oSketchEnt As SketchEntity
Dim StartX As Double = 0
Dim StartY As Double = 0
Dim EndX As Double = 0
Dim EndY As Double = 0

	For Each oSketchEntity In oSketch.SketchEntities
			StartX = oSketchEnt.StartSketchPoint.Geometry.X
			StartY = oSketchEnt.StartSketchPoint.Geometry.Y
			
			EndX = oSketchEnt.EndSketchPoint.Geometry.X
			EndY = oSketchEnt.EndSketchPoint.Geometry.Y
   	 Next

Dim oSketchLines As SketchLines = oSketch.SketchLines
Dim oSketchLine As SketchLine
Dim LineLength As Double = 0

	For Each oSketchLine In oSketchLines
			LineLength = LineLength + oSketchLine.Length*10
			MessageBox.Show(LineLength)
			LineLength = 0
	Next
Message 10 of 12
LukeDavenport
in reply to: mk92

 

Change 

For Each oSketchEntity In oSketch.SketchEntities

To:

 

For Each oSketchEnt In oSketch.SketchEntities

That might do it.

Nice work

Luke 

Message 11 of 12
mk92
in reply to: LukeDavenport

Thanks! Got it a little bit different. Exactly after i have postet my question here. I did the Start and Endpoint thing in the ForEach Together with the lenght, so I can differentiate between arcs and lines.

Message 12 of 12
mk92
in reply to: LukeDavenport

Is it possibly to do this:

 

Dim oAssDoc As AssemblyDocument
oAssDoc = ThisApplication.ActiveDocument

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oSketch As PlanarSketch
oSketch = oAsmCompDef.Sketches.Item("Sketch 2")

 

With a sketch in a part from an Assembly? Sketch 2 is in a part wich is built in an assembly. So i need to set the oSketch to Sketch 2 in this part.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report