Macro to build new plans on an imported part

Hi all 

I would like to be enlightened about the possibility or not, of creating plans with predefined names. I only work on imported parts and I don't often like the original layout of the plans. So I would like to know if there is a technique to make their creation automatic and that the name will always be the same depending on the plan created. 

Thank you 

Hello

Yes, it is possible to create plans by code.

The problem is that you need references to create plans. So, by macro, apart from avoiding you to click on a new plan, you will have to select the references in advance, which makes it useless, in my opinion, to use a macro.

If you know, do fairly advanced macros, you can create a selection class, dynamically create a form, put the combinations of selections in a collection, go through that collection to create the outlines. (about 4 hours of programming for a connoisseur)

Following this principle, you fill in the form with all your selections and launch the macro that will take care of creating the plans.

1 Like

Hello Jean-Luc Villamy, a similar subject has already been discussed, maybe it can suit you? http://www.lynkoa.com/forum/electrique/macro-pour-changement-dorientation-des-vue-sous-solidworks

Otherwise we can see if you send us an example file with the plan to be created:)

1 Like

@Yves.T I'm only new to VBA code, and these steps you describe seem infeasible for my coding level. I was hoping that someone would have a macro frame as close as possible to what I want to do that I can modify to fit my needs. 

@Mad yes I know it since I was the one who posted this topic:) I managed to adapt the macro you gave me to work my way. In this case , I am no longer trying to change the orientation of my part in relation to the coordinate systems, but I am creating new planes that have a defined name according to the coordinate system (x;y; z). For example, NOM_PRENOM_FACE and that for the three planes... FACE... DOITE and ... ABOVE the marker, so that when I launch the macro I just have to constrain them as I wish. The problem with the macro you gave me is that some parts don't have the constrained planes on the surfaces I would like, so this macro doesn't touch my problem directly. 

I hope I have been clear enough about what I am looking for, thank you for helping me in my process and for being so patient !

Edit: the reason for wanting to modify the original plans of the STEP import of the part comes from the fact that the resulting view in the drawing doesn't show what I want from the part. 

The macro recorder gives this code for the generation of three planes at 100mm distance

Dim swApp As Object

Dim Part As Object
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc
boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
Dim myRefPlane As Object
Set myRefPlane = Part.FeatureManager.InsertRefPlane(8, 0.1, 0, 0, 0, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan de face", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan de dessus", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Plan de dessus", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
Set myRefPlane = Part.FeatureManager.InsertRefPlane(8, 0.1, 0, 0, 0, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan de dessus", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan de droite", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
boolstatus = Part.Extension.SelectByID2("Plan de droite", "PLANE", 0, 0, 0, True, 0, Nothing, 0)
Set myRefPlane = Part.FeatureManager.InsertRefPlane(8, 0.1, 0, 0, 0, 0)
Part.ClearSelection2 True
boolstatus = Part.Extension.SelectByID2("Plan de droite", "PLANE", 0, 0, 0, False, 0, Nothing, 0)
Part.ClearSelection2 True
End Sub

 

This macro does not produce any changes on my piece apart from making my shots shine very succinctly... Did I have to change a few lines to make it work?

Yes, the elements to be modified are the names of the plans

I tried to modify everything for the names of the planes, nothing to do when I launch the macro, it builds me others with the names Plan 12, Plan 13 and Plan 14. I admit I don't really understand why it doesn't work, I tried all the possible combinations

Mea culpa after checking on a new piece does not indeed it generates nothing I look at its

No problem, thanks for the help, I'll end up knowing how to code by dint of looking at the codes to know where it gets stuck!

I searched a lot and unfortunately I can't find anything existing on the web... My problem could also be solved if the macro renames the plane I designate for it, for example a macro for the front plane etc.  with a name that I define for him. I don't care if I have a lot of macros in my SW taskbar. I only want to automate the entry of text which wastes my time in the long run so a macro by shot name is not annoying.

You just want to rename planA to plan1?

I found the solution, I record a macro when I rename the shots that I would have created just before so that shot 1 is NOM_Face etc for the other shots, that is to say my macro will find the name of the shots edited before and which always have the same callsigns so it's up to me to force myself to follow an order to locate the one that is from face etc when I create them. 

On the other hand now I'm looking to record a macro when I perform a constraint on two planes that will always have the same names for the time being, but SW doesn't want to know anything about the constraints apparently... Has anyone ever made a macro to increment the constraints of setting planes (positioning in the ASM)

This is the macro that allows me to automatically rename the clips I created beforehand. Don't forget to impose a construction order, to organize your drawing views.

 


renommer_les_plans.txt