Hello On the UserForm1 record, there is a [Clear] button that deletes the 3D sketch and the coordinate system associated with the cube. Provided that these are the last two functions of the tree, so that nothing is added after the cube is created.
As for retrieving the name of a sketch, the " Name " method is part of the " ISketch " class of the API (" swSketch.Name ", see line 377).
But if you have a variable pointing to the sketch, such as line 363 (" Set swSketch = swModel.SketchManager.ActiveSketch "), the " Select4() " method allows selection without having to search for its name, for example: " ok = swSketch.Select4(False, Nothing) " Probably inherited members, they are not documented in the help of the " ISketch " class, but are documented in other...
Hello @m.blt Thank you once again for your feedback. I hadn't hit for the DELETE button actually. I'll take a closer look at this to see when it acts in relation to the information of the variables I added... and to enrich my intellectual poverty in VBA .
By the way, in VBA I tinkered with it this morning... A macro that retrieves the name of the last function in order to delete it. As there is a 3D sketch and a trihedron, I double the command lines to remove the 2 functions. I know, it's archaic There is surely a way to make it simpler I guess ...
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swDoc As SldWorks.ModelDoc2
Dim swAssembly As SldWorks.AssemblyDoc
Dim swFeatureName As SldWorks.Feature
Sub SuppressionDeuxDernieresFonctions()
Set swApp = Application.SldWorks
Set swDoc = swApp.ActiveDoc
' Vérifie que le document SW est ouvert
If swDoc Is Nothing Then
MsgBox "Aucun document Solidworks ouvert"
Exit Sub
End If
Set swAssembly = swDoc
'''Première passe pour supprimer le trièdre
'Attribution nom dernière fonction
Set swFeatureName = swDoc.Extension.GetLastFeatureAdded
'Vérifie la selection de la fonction
If swFeatureName Is Nothing Then
MsgBox "Sélection fonction impossible"
swDoc.ClearSelection2 True
Exit Sub
End If
'Selection du nom
swFeatureName.Select True
'Suppression de la fonction
swDoc.EditDelete
'''Deuxième passe pour supprimer l'esquisse 3D
'Attribution nom dernière fonction
Set swFeatureName = swDoc.Extension.GetLastFeatureAdded
'Vérifie la selection de la fonction
If swFeatureName Is Nothing Then
MsgBox "Selection fonction Impossible"
swDoc.ClearSelection2 True
Exit Sub
End If
'Selection du nom
swFeatureName.Select True
'Suppression de la fonction
swDoc.EditDelete
End Sub
I have a small question about the definition of the layout of the box. I have a few cases where it doesn't totally fit at the maximum of what should be. In particular on round parts with fillets:
Hello It is difficult to say what the origin of the problem you are raising. A few remarks:
What is the magnitude of the error, compared to the general dimensions of the assembly (in mm for example)?
Insofar as the observed defect requires a significant zoom, the display may be to blame...
The " GetExtremePoint() " method determines the outer limit for each part. This is a numerical calculation internal to the SolidWorks APIs. Is it rigorous? Like any numerical calculation, it uses a quality criterion to validate its search, a criterion unknown to the user. On this point, SolidWorks Help comment about the " GetBodyBox " function which apparently uses the " GetExtremePoint " method: IMPORTANT : The values returned are approximate and should not be used for comparison or calculation purposes. In addition, the bounding box may vary after the model is rebuilt. The outlines of the " clouds" visible in the screenshots appear to be based on splines. Could this be the origin of the pb?
The only calculations inside the macro are coordinate system changes that use the API's vector and raster functions. I don't see how they can generate the defect.
To conclude: I am not in a position to identify the origin of the problem. Can you share the example that is problematic? Even if it is degraded, or by private message...
So the error varies according to the assemblies and parts. This ranges from 0.5 to 1.5mm. In my case this is not necessarily important, because I get my values back to the cm.
My question was mainly in order to better understand the code and possibly correct it if it was feasible. So nothing imperative.
I still put the assembly + parts with 3D Sketch + System coordinates generated by the macro if you want to look.
Great job @m.blt , as always. And I thought I'd never have to use the " BoundingBox " until now... I come across a client, let's say... Fussy. Your Macro is therefore timely. Thank you
Hello @Maclane , and thank you for the compliment... However, beware of the problem of precision raised by @MLG in his last message. I noticed the anomaly, but I couldn't identify if it's SW or the macro that is at fault.
Hello; This is a recurring problem with splines, Solidworks only takes into account the points and not the curve itself so I think the " GetExtremePoint() " function does the same thing (as its name suggests).
For my part, I took the liberty of modifying your macro by adding the properties to the document with an option to register them (or not) in all configurations. On the other hand, I'm looking for how to add dimensioning on the 3D sketch.
I haven't looked at the notion associated with the " Delete " button yet, but I think that by renaming the " 3Dsketch " and " Coordinate System" functions in a more explicit way (like " BoundingBox_3D " and " BoundingBox_XYZ "), it will be easier to delete them, or even to delete all the functions (leftovers) with the same Names (+counter).
Hi all The difference is really minimal but is indeed present. Having documents listed by hand and some using this macro, we ended up with different output data, hence my question... And for splines, we avoid working with them so as not to have this kind of problem.