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: 

Need macro/plug in to project planes on sketch

10 REPLIES 10
SOLVED
Reply
Message 1 of 11
mwhite
1037 Views, 10 Replies

Need macro/plug in to project planes on sketch

Hi guys, first of all let me admit that I know nothing about VB or IVB Smiley Happy or I would have a go at this myself. I create many sketches each day to create this feature or that. I always like to project the two relevant origin planes (the two that I'm not sketching on) onto the sketch as construction lines (see screen shots). Then use these lines to dimension from, if it's practical. What I would ideally love to have is some kind of macro/plugin (not sure of the term) that would project these planes as soon as the sketch plane is identified and I go into sketch mode. But I'd be happy to have a little macro button that I could hit, maybe from my marking menu, and this macro would then project the planes.

 

If someone might happen to have something that would meet these needs that would be great. If I'm asking something that's very time consuming please just ignore this post.

 

Capture1.jpg is a simple part with the planes as I'd like to have them projected. In Capture2.jpg I've a added a center point with dim's to the planes to illustrate their use.

 

 

thanks in advance for any help,

Mike

10 REPLIES 10
Message 2 of 11
philippe.leefsma
in reply to: mwhite

Hi Mwhite,

 

Several things here: first of all that's not a forum where you'd post jobs for other people to do it for you. Supposing somebody over there has enought free time and willingness to implement and package for you the whole thing, that's great, but I'd think this is going to be unlikely.

 

Rather what we do here is provide support and guidance to people who have already little knowledge in programming and who can use the instructions or sample code we point out to accomplish what they need.

 

If you are a novice in Inventor programming and want to take the step, here are useful resources:

 

http://usa.autodesk.com/adsk/servlet/index?siteID=123112&id=17324828

 

https://github.com/ADN-DevTech/Inventor-Training-Material

 

The other thing is that what you're asking for here is going to need to cover several aspects of the API: UI customization, work with the part API and so on...

 

Also projecting a plane on a sketch has no meaning in general, in the case they are perpendicular you will get an infinite line, but in case they are not, there is no mathematical meaning to that projection. What you should rather do is projecting two points that represent a direction on your sketch.

 

Supposing you have a little experience with the API, the following code sample should help you to figure out how to project a point on a selected workplane: a sketch is always based either on a workplane or a planar face, so you can extract the underlying Plane from a specific sketch:

 

Private Function ProjectOnPlane(point As point, plane As plane) As point

    Dim measureTools As measureTools
    Set measureTools = ThisApplication.measureTools
    
    Dim minDist As Double
    Dim Context As NameValueMap
    
    minDist = measureTools.GetMinimumDistance(point, plane, kNoInference, kNoInference, Context)
    
    Dim projectedPoint As point
    Set projectedPoint = Context.item(2)

    Set ProjectOnPlane = projectedPoint
    
End Function

Public Sub ProjectOnPlaneTest()

    Dim wp As workplane
    Set wp = ThisApplication.CommandManager.Pick(kWorkPlaneFilter, "Select a workplane:")
    
    If wp Is Nothing Then
        Exit Sub
    End If
    
    Dim vertex As vertex
    Set vertex = ThisApplication.CommandManager.Pick(kPartVertexFilter, "Select a vertex:")
    
    If vertex Is Nothing Then
        Exit Sub
    End If
    
    Dim point As point
    Set point = ProjectOnPlane(vertex.point, wp.plane)
    
    Debug.Print "Projected point: [" & point.X & "; " & point.Y & "; " & point.Z & "]"
    
End Sub

In that other post I illustrate how to customize the marking menu with custom commands:

 

http://adndevblog.typepad.com/manufacturing/2012/05/customizing-radialmarkingmenu-and-linearmarkingm...

 

This information should help you to get started with implementing the required functionality.

 

If you have more specific questions, feel free to ask or log a new thread in our forum.

 

Regards,

Philippe.



Philippe Leefsma
Developer Technical Services
Autodesk Developer Network

Message 3 of 11
mwhite
in reply to: mwhite

My mistake, I looked and couldn’t find the actual purpose of the forum other than the name which is pretty general. Also as I mentioned above I didn’t want someone to spend a lot of time on this, I was hoping this might be a tool that someone else had created and would give me a copy.

 

I don’t quite understand what you mean about the plane on sketch having no meaning in general or mathematically. The projected planes are used to dimension off of to insure a feature doesn’t move if the part geometry changes (see screen shots). I’ve been working with Inventor and Pro-E for about 12 years and found this to be a very common work practice. The lines aren’t infinite because Inventor shows the length as not being constrained.

 

Thanks for the links. The first one I intend to work through as soon as our IT guys approve the install of Microsoft Visual Basic Express. The other two look very helpful.

 

Mike

Message 4 of 11
adam.nagy
in reply to: mwhite

Hi Mike,

 

You should give the API a try yourself, because it is not as difficult as you may think 🙂

 

Also, in order to get started you don't even have to install anything, since there are two enviroments installed as part of Inventor from where you can use the API: VBA and iLogic. Check them out!

 

I wrote a VBA sample that I think does what you are after. You can hook it up to a button in the UI if you want to:

http://adndevblog.typepad.com/manufacturing/2014/02/project-perpendicular-origin-planes-into-sketch....

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 5 of 11
mwhite
in reply to: adam.nagy

Hey Adam thanks a ton man!! I'm going to see if I can get this thing on my toolbar this morning. I'm always looking for apps/add-ins to make work more productive but many times I can't find the one I need  (hence the post). So I've been thinking about learning at least some API basic stuff. Would you recommend the tutorials mentioned above?

 

thanks again,

Mike

Message 6 of 11
mwhite
in reply to: adam.nagy

hi Adam, we got this hooked up to a macro button, even put it in my marking menu. I already love it, there's only two things that would really help if added, sorry if I'm looking a gift horse in the mouth i do appreciate your help. The first is if the planes could be construction instead of solid. The second is I have to have the part open in it's own window. I can't just activate it in  assembly mode and edit it there, which is something I use often. As I said before if this is a big request of your time please just ignore.

 

thanks,

Mike

Message 7 of 11
adam.nagy
in reply to: mwhite

Hi Mike,

 

If I understood you correctly then it is easy. Only three things needed to be changed:

- use ActiveEditDocument instead of ActiveDocument so we get back the part document even if it's edited inside an assembly document

- use SketchEntity.Construction = True

- use ActiveDocument.Update to make the lines appear in case of an assembly document

Public Sub ProjectPerpendicularOriginPlanes()
  Dim doc As Document
  ' This works even if the part document is activated inside
  ' an assembly and not opened in its own window
  Set doc = ThisApplication.ActiveEditDocument
  
  If Not TypeOf doc Is PartDocument Then
    Call MsgBox("You need to be inside a part document")
    Exit Sub
  End If
    
  Dim ao As PlanarSketch
  Set ao = ThisApplication.ActiveEditObject
  
  If Not TypeOf ao Is PlanarSketch Then
    Call MsgBox("You need to be inside a sketch")
    Exit Sub
  End If
  
  Dim pd As PartDocument
  Set pd = doc
  
  Dim cd As PartComponentDefinition
  Set cd = pd.ComponentDefinition
  
  Dim sk As PlanarSketch
  Set sk = ao
 
  ' The origin planes are the first 3
  ' in the WorkPlanes collection
  Dim i As Integer
  For i = 1 To 3
    Dim wp As WorkPlane
    Set wp = cd.WorkPlanes(i)
      
    ' If the WorkPlane was already added
    ' then AddByProjectingEntity would throw
    ' an error.
    ' To avoid that we can do error handling:
    On Error Resume Next
    
    If wp.Plane.IsPerpendicularTo(sk.PlanarEntityGeometry) Then
      ' Checking if the workplane is perpendicular might
      ' be an overkill because if not, then the below
      ' function would throw an error.
      ' But I think it's nicer if we check :)
      Dim se As SketchEntity
      Set se = sk.AddByProjectingEntity(wp)
      ' Make the line a construction line
      se.Construction = True
    End If
    
    On Error GoTo 0
  Next i
  
  ' Get things updated so the new sketch lines show
  ' even if the part document is modified inside an assembly
  ThisApplication.ActiveDocument.Update
End Sub

Yes, the resources Philippe pointed are a good starting point. This could also be useful: http://adndevblog.typepad.com/manufacturing/2013/10/discover-object-model.html

 

PS: Could you please mark one of the replies as solution?

 



Adam Nagy
Autodesk Platform Services
Message 8 of 11
mwhite
in reply to: adam.nagy

Thanks Adam, worked perfect, just what I needed.

 

Mike

Message 9 of 11
PaulPink1017
in reply to: mwhite

Mike,

This is the first time I have used the forum, and, my thoughts are like yours. I came looking for the same thing you did.

The response from Mr. Leefsma was way out of line. First of all his attempt to question why you came to the forum with this type of question, second, he must not design machines to ask why you would project all planes into your sketch.

We always mate parts using planes. This allows us to change material size without having to edit the mate to accommodate a thickness / width change. We also try to use symmetry in our designs for the same reason.

We used to project the planes on our first sketch of all parts. We have found that it is not necessary when the first sketch is a rectangle or circle. By using the center point rectangle or center point circle drawn on the Origin and then using a mid plane extrusion, the planes are in the center of the first feature. However, if you want to dimension off the center you have to project the axis.

Subsequent sketches on the the part start with the origin on the bottom left edge of the side of the part you want the sketch on. If you want it about the middle of the part, you have to go through and project all.

Hopefully we can figure out the VB. A nice feature might be drop down menu choices when you click Project Geometry that lets you Pick either 'All Axis", "All Planes", or both.

Thanks, Mike

Message 10 of 11
mwhite
in reply to: mwhite

thanks for the support Paul,

yeah it gripes me that he criticizes me with evidently not reading my post. I made it abundantly clear that if this was a time consuming request (seeing as how I know nothing about VB as i admitted) to ignore it. Even put in a nice disarming smiley face lol. The reason for the request to ignore my post is from past experience. More than once I've made a reasonable request or question only to receive some snide response. A fair share of these were from autodesk support ppl. Although I'm really interested in IV customization replies like that just make me not want to post or ask questions at all. Also his comment about projecting a plane to a sketch just befuddles me. I've worked with droves of engineers and designers in my 49 years and I've never met any that didn't use this often. Honestly I don't see how he could have a working knowledge of IV and make that statement.

 

On the other hand the response from adam.nagy was polite and encouraging. Even wrote me a macro/program (not sure of the term) which works great.

 

Mike

 

 

Message 11 of 11
mwhite
in reply to: mwhite

 

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

Post to forums  

Autodesk Design & Make Report