Hello
In my drawings on SolidWorks, I have a "verification: 1" block. I'd like to increment the 1 automatically at insertion. Is there a possibility? I can use a macro if I have to, but I don't know the code to retrieve my attribute.
Thank you and have a good day
Hello, do you have a variable in the $prpsheet....... block?
For my part I prefer to use an annotation
Verification: "$PRPSHEET xxxxxx:"
Hello
For the moment I have an internal variable in the block so as not to overload the custom properties of my plans. I change it manually but it would save me time if the number changes itself with each click (I have on average about 60 blocks to insert)
Hello, I take the liberty of bringing up this post that I had launched during the server fires. If there is no solution I will close but in doubt... :)
Hello
This will add a note with increments:
Option Explicit
Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swDraw As SldWorks.DrawingDoc
Dim swSheet As Sheet
Dim swPt As Variant
Dim Txt As String
Dim Max As Integer
Dim swNote As SldWorks.Note
Dim swView As SldWorks.View
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swDraw = swModel
Set swSheet = swDraw.GetCurrentSheet
Set swView = swDraw.ActiveDrawingView
swPt = swDraw.GetInsertionPoint
If IsEmpty(swPt) Then MsgBox ("Un point doit être sélectionné"): Exit Sub
Txt = "vérification : "
Max = FindMax(swDraw, Txt)
swDraw.ActivateSheet swSheet.GetName
Set swNote = swDraw.InsertNote("<FONT color=0x000000ff><FONT style=B>" & Txt & Max + 1)
swNote.SetTextPoint swPt(0), swPt(1), 0
swNote.Angle = 10 * 3.1416 / 180
If swView Is Nothing Then Exit Sub
Dim swAnn As SldWorks.Annotation
Dim vEnts As Variant
Dim swEnt As SldWorks.Entity
Set swAnn = swNote.GetAnnotation
swAnn.Select3 False, Nothing
vEnts = swView.GetVisibleEntities2(Nothing, swViewEntityType_e.swViewEntityType_Face)
Set swEnt = vEnts(0)
swDraw.AttachAnnotation swAttachAnnotationOption_e.swAttachAnnotationOption_View
End Sub
Function FindMax(ByVal swDraw As SldWorks.DrawingDoc, ByVal Txt As String)
Dim Max As Integer
Dim vSheetName As Variant
Dim i As Integer
Dim swView As SldWorks.View
Dim swNote As SldWorks.Note
Dim vNotes As Variant
Dim vNote As Variant
vSheetName = swDraw.GetSheetNames
For i = 0 To UBound(vSheetName)
swDraw.ActivateSheet vSheetName(i)
Set swView = swDraw.GetFirstView
While Not swView Is Nothing
vNotes = swView.GetNotes
For Each vNote In vNotes
Set swNote = vNote
Dim NoteTxt As String
NoteTxt = swNote.GetText
If NoteTxt Like Txt & "*" Then
'Debug.Print NoteTxt
Dim Str() As String
Str = Split(NoteTxt, ": ")
If Str(1) > Max Then Max = Str(1)
End If
Next
Set swView = swView.GetNextView
Wend
Next
FindMax = Max
End Function
1 Like
Thank you I'll try with this! Thank you for the time.