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


Categories: API∕Macros

Comments
Last comment By: Hector Molina   Mon, 21 May 2018 12:48:08 GMT
Re: Initiate point command in a sketch vba

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.

By: Deepak Gupta  Tue, 15 May 2018 16:38:24 GMT
Re: Initiate point command in a sketch vba

Thank you for you quick reply Deepak, I will look into it.

 

Enjoy your day,

 

Hector

By: Hector Molina  Tue, 15 May 2018 16:44:48 GMT
Re: Initiate point command in a sketch vba

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

By: Nilesh Patel  Tue, 15 May 2018 21:20:07 GMT
Re: Initiate point command in a sketch vba

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

By: Hector Molina  Wed, 16 May 2018 12:42:28 GMT
Re: Initiate point command in a sketch vba

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

By: Nilesh Patel  Wed, 16 May 2018 21:44:19 GMT
Re: Initiate point command in a sketch vba

Hello Nilesh,

 

Thank you so much for your help on this. My preference regarding the creation of the new geometry would be to first, select face, place the point by using relations, or dimensions, then use the new point to create a plane perpendicular to the selected face, and create the sketch for the revolved surface, then use "revolve surface".

 

I will give your suggestions a try, hopefully I can figure it out correctly. I greatly appreciate your kindness on this issue, I may take a little while to get it done, as the workload permits. I will let you know how it goes.

 

Have a great day,

Thank you once again,

 

Hector

By: Hector Molina  Thu, 17 May 2018 12:15:08 GMT
Re: Initiate point command in a sketch vba

Hector,

This would be vastly simpler to program if you simply had the user go ahead and create and then select the sketch before running the macro.  You can then get the selected sketch, find all the sketch points, and insert your surfaces. It's a much cleaner transition between the user action and the macro action.

 

As a longtime user of SW, I actually wish I could pre-create the location sketch for hole wizard holes as well.  I have some macros that are helpful during sketch creation, but while the hole wizard is active you can't run a macro.

By: Josh Brady  Thu, 17 May 2018 14:44:14 GMT
Re: Initiate point command in a sketch vba

Josh,

Thank you for your advise, if that makes it simpler, then that is the way to go. Not being a programmer, I don't believe that my programming logic is that good. I really need to understand the API, and how VBA works better. I am starting to see that I am biting more than I can chew.

 

Thank you for your advise, Josh. I appreciate you taking the time to guide me on this.

By: Hector Molina  Thu, 17 May 2018 14:56:50 GMT
Re: Initiate point command in a sketch vba

Hi Hector,

 

As Josh Brady mentioned, it will be lot easier for you to create a sketch point manually. Have a look at the example to insert the reference plane to create the sketch: 2018 SOLIDWORKS API Help - Insert Reference Plane Example (VBA)

 

I couldn't find any example to insert revolve surface.

 

Good luck.

 

Regards,

Nilesh

By: Nilesh Patel  Sun, 20 May 2018 21:31:06 GMT
Re: Initiate point command in a sketch vba

Hello Josh,

 

Thank you so much for looking into it for me. I will try it that way.

By: Hector Molina  Mon, 21 May 2018 12:48:08 GMT
You are not authorized to view this page No results found! Suggestions: Check spelling, try a different search, or browse topics below.