10 Replies Latest reply on May 21, 2018 8:48 AM by Hector Molina

    Initiate point command in a sketch vba

    Hector Molina

      Hello Everyone,

       

      Thank you for reading my question, your interest, and help is greatly appreciated. I am new to VBA, new to programming actually, and I am trying to figure things out.

      I need to have the user put a sketch point on a face, but have not been successful.

      The goal is to create a custom made hole on a part, I have searched the help/web and found good examples of code (Big thanks to all the people who have made their code available to assist others), and have been able to start the macro, pause, and wait for the user to click a face on a part, insert a sketch, and that's as far as I get. At this point I want to start the point command for the user, I figure, why have them click the point icon when I can get that done for them. I can't find a way to do that. All examples I find work by preselecting the face, or plane to sketch on. Even when I record a macro, I have to preselect the face before running it, to get the point in place. Could you please point me in the right direction?

       

      Thank you for your help,

       

      Hector

        • Re: Initiate point command in a sketch vba
          Deepak Gupta

          I'm not on the system but check RunCommand method but you must have a plane/surface selected for a 2d sketch. in case you need 3d sketch, then no selection would be required.

          • Re: Initiate point command in a sketch vba
            Nilesh Patel

            Hi Hector,

             

            You mentioned that you would like to create a custom hole and what is the reason to create a sketch point. Could you explain your end goal in detail? This will help us guide you in right direction.

             

            Regards,

            Nilesh

              • Re: Initiate point command in a sketch vba
                Hector Molina

                Hi Nilesh,

                 

                Thank you for your interest, and taking the time to ask. My description is not clear, I intended it to be concise, but it is not really representative of what I mean to accomplish.

                When we detail die plates, and punch holder plates for our stamping dies, depending on their size, there is a need to clamp them down on a milling machine/jig grinder. But sometimes, having a clamp in the way is not very helpful. So, my company has us put 5/16 counterbore holes on the plates to screw them down instead of the clamp. Sometimes we can simply use the Holewizard, and we put the hole and never gets used again, no problem, but sometimes, we need to put them in an area where a cavity is going to be wired cut. That wired cut hole/pocket is used for trimming inserts. So placing a Holewizard hole does not work, because there is no place to put it on the plate, just a cavity. So now we use a surface in the shape, and size of the counterbore.

                We cannot insert these "fake" holes using "insert block" command, and if we create them and save them, then we need to use the "insert part" command, and then we need to use the "move/copy body" command to place it.

                I thought it would be easier to just have the user invoke the macro, select the plate's face, then click for a sketch point location, whether on the face  located with dimensions, or concentric to an existing hole.

                 

                Thank you for your help,

                Hector

                RectangularHoleEnd.PNGRoundHoleEnd.PNG

                  • Re: Initiate point command in a sketch vba
                    Nilesh Patel

                    Hi Hector,

                     

                    Thank you for the detailed explanation. You have two choice here:

                     

                    1. As Deepak Gupta mentioned use, IModelDocExtension::RunCommand method and specify 'swCommands_e.swCommands_Point' as 'CommandID' parameter (User will still need to select the face or plane to create this sketch point) where user can place create dimensions to fully define this sketch point, or

                     

                    2. Ask user to select the face and two edges if the cavity is rectangular or one edge if the cavity is cylindrical before running the macro and insert the sketch point using ISketchManager::CreatePoint method and fully define the sketch point using ISketchManager::FullyDefineSketch method. In case of two edges selected for rectangular cavity, you can show a simple user form to enter the dimensions from edge1 and edge2. In case of one edge for cylindrical cavity, you use its centre point to fully define the newly created sketch point. This approach is complicated than first one.

                     

                    If I understood you correctly, once you create the sketch point, you would like to insert the a part into an active part using command 'Insert Part' and use 'move/copy body' command to locate it. Is this is the case, then you can use original face selected and the newly created sketch point to insert the part into a part document using 'IPartDoc::InsertPart2' method and locate it using 'IFeatureManager::InsertMoveCopyBody2' method.

                     

                    Let us know if you get stuck.

                     

                    Regards,

                    Nilesh