Let's say I have a preselected note on solidworks 2D drawing,
that I would like to delete.
I couldn't find any members for INote or IAnnotation,
that would do this.
Some pointers are highly appreciated.
Thanks in advance.
Select the note and then use IModelDoc2::EditDelete
Here is a bit of code I've used in the past to delete a note (you'll need the name of the note, or a pointer to it)
'Select the temporary note and delete it
swModel.Extension.SelectByID2 swNoteTemp.GetName, swSelNOTES, 0, 0, 0, False, 0, Nothing, 0
I am looking into this as well... haven't gotten it completely figured out.
I'm looking at the example of how to create a block with vba.
But this should help you in the write direction.
Dim swSkNote as SldWorks.Note
set swSkNote = swModel.getselected (or whatever that is to get the selected object)
I haven't tried it yet though....
Here is macro created by Deepak Gupta, that inserts blocks with vba. It may be helpful for you.
'Insert Block at specified Location.swp ------------- 10/03/13
'Description: Macro to Insert Block at specified Location in active drawing sheet.
'Pre-Condition: Any active Drawing document. User needs to pick point on drawing sheet before running the macro.
'Post-Condition: Macro will Insert specified Block at specified Location.
' Please back up your data before use and USE AT OWN RISK
' This macro is provided as is. No claims, support, refund, safety net, or
' warranties are expressed or implied. By using this macro and/or its code in
' any way whatsoever, the user and any entities which the user represents,
' agree to hold the authors free of any and all liability. Free distribution
' and use of this code in other free works is welcome. If any portion of
' this code is used in other works, credit to the authors must be placed in
' that work within a user viewable location (e.g., macro header). All other
' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited
' without the expressed written consent by the authors. Use at your own risk!
' Written by: Deepak Gupta (http://gupta9665.com/)
Dim swApp As SldWorks.SldWorks
Dim swSktManager As SldWorks.SketchManager
Dim SelMgr As Object
Dim swModel As SldWorks.ModelDoc2
Dim swMathUtility As SldWorks.MathUtility
Dim swMathPoint As SldWorks.MathPoint
Dim PointCoords(2) As Double
Dim swSktBlkDef As SldWorks.SketchBlockDefinition
Dim swSheet As SldWorks.Sheet
Dim scl As Double
Dim angle As Double
Dim PickPt As Variant
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
If (swModel Is Nothing) Then
MsgBox "No active file found in SolidWorks." & Chr(13) & Chr(13) _
& "Please load/activate a SolidWorks Drawing and TRY again!", vbExclamation
If (swModel.GetType <> swDocDRAWING) Then
MsgBox "Current file is not a SolidWorks Drawing." & Chr(13) & Chr(13) _
& "Please Open/Activate a SolidWorks Drawing and TRY again!", vbExclamation
Set swSktManager = swModel.SketchManager
Set swMathUtility = swApp.GetMathUtility
Set swSheet = swModel.GetCurrentSheet
Set SelMgr = swModel.SelectionManager
' Get the user's pick-point coordinates
PickPt = SelMgr.GetSelectionPointInSketchSpace(1)
' If no selection was made, then return an error message to the user
If (SelMgr.GetSelectedObjectCount = 0) Or (IsEmpty(PickPt)) Then
swApp.SendMsgToUser ("Select a Location first...")
' Otherwise, Insert Block
' Change the insert point here. You will need to set the final coordinates here
PointCoords(0) = PickPt(0) ' X
PointCoords(1) = PickPt(1) ' Y
PointCoords(2) = PickPt(2) ' Z
Set swMathPoint = swMathUtility.CreatePoint(PointCoords)
' Change scale and angle here
scl = 3
angle = 0
' Change path and file name of block in the follwoing line. Changing True to flase will unlink the block to original file.
Set swSktBlkDef = swSktManager.MakeSketchBlockFromFile(swMathPoint, "C:\Users\ks\Desktop\Macro\MyMacro\Block51.SLDBLK", False, scl, angle)
And I believe that INote doesn't have method delete. I already looked at selection manager, note, and annotation.
Hopefully tmrw I'll figure it out
Thank you it worked.
Perhaps you can help me with my other problem. I'm trying to select note using swModel.Extension.SelectByID2 and known name, but it doesn't want to select it. They only way is to put coordinates, but those won't be available when using macro. Also i can't loop throught the views since these notes are not attached to views.
Thank you one more time.
Actually, looping through the views should work. The Sheet Format is considered a view by the API.
Thank you. It didn't work at first but now it does.
Two different ways to get it:
While Not (swView Is Nothing)
Set swNote = swView.GetFirstNote
While Not (swNote Is Nothing)
noteName2 = swNote.GetName
Debug.Print "8888888*********" & noteName2
Set swNote = swNote.GetNext
Set swView = swView.GetNextView
Set swView = swDraw.GetFirstView
Set swAnno = swView.GetFirstAnnotation2()
While Not (swAnno Is Nothing)
noteName2 = swAnno.GetName
Debug.Print "9999999*********" & noteName2
Set swAnno = swAnno.GetNext
Klaudiusz, do you mind sharing your complete macro? Thank you!
I can't as I developed that macro for local business. You can always shoot me a question.
Retrieving data ...