How do i automate clicking a square in a 2d sketch to make a larger square that offsets the original and makes corner cutouts?

How do i automate clicking a square in a 2d sketch to make a larger square that offsets the original and makes corner cutouts?

Anonymous
Not applicable
732 Views
2 Replies
Message 1 of 3

How do i automate clicking a square in a 2d sketch to make a larger square that offsets the original and makes corner cutouts?

Anonymous
Not applicable

I was able to command-bash macros in excel using the macro recorder.

 

However inventor doesnt have any such function, im wondering how i would write a macro that does this.

The steps are:

 

1. Run Macro

2. Select a square/rectangle

3. This triggers the macro to use Offset command to create a square/rectangle with sides that are .001" equidistant

4. Draw circles (0.06") at each of the four corners of the offset square/rectangle 

5.Done

 

Currently i can see how steps 1 and 5 would work with everything else being a blackbox. If anyone can guide me to a sample code that mimicks what I need, I could probably stumble my way to a solution.

 

Thanks!

 

0 Likes
733 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor

try this. its not the best code but i quess its a good start. (also have a look at the comments in the code) you can use it by running the ilogic code. then select a sketch (with a square) then select the square. And look what happens.

Dim doc As PartDocument = ThisDoc.Document
Dim sketch As PlanarSketch = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Select a sketch") sketch.Edit() 'selecting a square/rectangle is not an option that i could find. but you could select a profile. 'i use it here but it will only work if there is none geometry inside the square/rectangle Dim profile As Profile = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kSketchProfileFilter, "select a square/rectangle") Dim objs As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection() Dim cornerPoints As List(Of Point2d) = New List(Of Point2d)() For Each path As ProfilePath In profile For Each ent As ProfileEntity In Path objs.Add(ent.SketchEntity) cornerPoints.Add(ent.StartSketchPoint.Geometry) cornerPoints.Add(ent.StartSketchPoint.Geometry) Next Next ' You need to use CM for distances Dim offsetEnts As SketchEntitiesEnumerator = sketch.OffsetSketchEntitiesUsingDistance(objs, 0.01 * 2.54, False) For Each ent As SketchEntity In offsetEnts sketch.SketchCircles.AddByCenterRadius(ent.StartSketchPoint.Geometry, 0.06 * 2.54 / 2) Next ' uncomment this lines if you want the cicles on the inner square 'For Each cornerPoint As Point2d In cornerPoints ' sketch.SketchCircles.AddByCenterRadius(cornerPoint, 0.06) 'Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

Message 3 of 3

Anonymous
Not applicable

Thanks @JelteDeJong ! Illtry it out at work, this will give me a good base to go off of

0 Likes