Macro per aggiungere nota su drw multifoglio

IronCad

Utente poco attivo
professione: Studente
software: Solidworks
regione: veneto
Buon pomeriggio,
sto cercando di realizzare una macro per automatizzare il processo di aggiunta di una specifica nota a tutti i fogli di un file. slddrw,
Vorrei che lanciando la macro ai fogli del file che ho aperto si aggiunga una nota.
Allego ciò che ho realizzato che non riesco a far funzionare perchè il sistema mi dà errore run-time che allego.

Ringrazio chi può aiutarmi.
1732199434834.png
 

Allegati

  • solidworks-macro.txt
    2.2 KB · Views : 2

jenuary

Utente Senior
professione: Progettista e Programmatore VB.Net
software: Solidworks
regione: Veneto
Ciao @IronCad
ho rivisto la tua macro, ho trovato un pò di errori, il principale era che i metodi che usavi per richiamare i fogli fanno parte del documento tavola (drawingdoc) mentre tu li richiamavi nel documento generico (object), infatti ti consiglio quando scrivi una macro di sovrascrivere i due oggetti principali in questo modo, così ti si attiva anche il menu dei metodi quanto premi il punto:
Dim swApp As Object 'Diventa
Dim swApp As SldWorks.SldWorks

'Per la tavola
Dim swDraw As Object 'Diventa
Dim swDraw As SldWorks.DrawingDoc

'Per la parte
Dim swPart As Object 'Diventa
Dim swPart As SldWorks.Partdoc

'Per l'assieme
Dim swAsm As Object 'Diventa
Dim swAsm As SldWorks.AssemblyDoc



Ad ogni modo ho riscritto tutto e ti ho inserito i commenti così capisci cosa sta facendo la macro nelle varie fasi.

Dim swApp As SldWorks.SldWorks
Dim swDraw As SldWorks.DrawingDoc
Dim boolstatus As Boolean
Dim longstatus As Long, longwarnings As Long
Dim sheetCount As Long, i As Long
Dim swSheet As SldWorks.Sheet


Sub main()

Set swApp = Application.SldWorks
Set swDraw = swApp.ActiveDoc

'Ricavo il foglio attivo in questo momento
Set swSheet = swDraw.GetCurrentSheet
vSheetNameArr = swDraw.GetSheetNames

'Ricavo il nome del foglio attivo in questo momento
'mi serve alla fine per riportare dopo il ciclo di inserimento delle note
'attivo il foglio di partenza
Dim Nsheet As String
Nsheet = swSheet.GetName

'Ciclo i fogli
For Each vSheetName In vSheetNameArr
bRet = swDraw.ActivateSheet(vSheetName): Debug.Assert bRet

Dim myNote As Object
Dim myAnnotation As Object
Dim myTextFormat As Object

'Inserisco la nota
Set myNote = swDraw.InsertNote("<FONT size=72PTS style=B>BOZZA")

'Ne definisco le caratteristiche, posizione, colore ecc
If Not myNote Is Nothing Then
myNote.LockPosition = False
myNote.Angle = 0
boolstatus = myNote.SetBalloon(0, 0)

Set myAnnotation = myNote.GetAnnotation()

If Not myAnnotation Is Nothing Then
longstatus = myAnnotation.SetLeader3(swLeaderStyle_e.swNO_LEADER, 0, True, False, False, False)


boolstatus = myAnnotation.SetPosition(0.115, 0.07, 0)

Set myTextFormat = swDraw.GetUserPreferenceTextFormat(0)
myTextFormat.Italic = False
myTextFormat.Underline = False
myTextFormat.Strikeout = False
myTextFormat.Bold = True
myTextFormat.Escapement = 0
myTextFormat.LineSpacing = 0.001
myTextFormat.CharHeightInPts = True
myTextFormat.TypeFaceName = "Century Gothic"
myTextFormat.WidthFactor = 1
myTextFormat.ObliqueAngle = 0
myTextFormat.LineLength = 0
myTextFormat.Vertical = False
myTextFormat.BackWards = False
myTextFormat.UpsideDown = False
myTextFormat.CharSpacingFactor = 1

'Applico le caratteristiche alla nota
boolstatus = myAnnotation.SetTextFormat(0, False, myTextFormat)

'Deseleziono qualsiasi selezione attiva e aggiorno la grafica
swDraw.ClearSelection2 True
swDraw.WindowRedraw
End If
End If
Next vSheetName

'Riattivo il foglio iniziale, altrimenti rimane sull'utimo foglio
bRet = swDraw.ActivateSheet(Nsheet)

End Sub
 

IronCad

Utente poco attivo
professione: Studente
software: Solidworks
regione: veneto
Grazie @jenuary, soprattutto per la spiegazione.
Sto cercando di studiare bene come si scrivono le Macro per solidworks ma sono un pò alle prime armi.
Avresti consigli da darmi o materiale da cui studiare per imparare questo tema?

Grazie ancora...
 

Statistiche forum

Discussioni
59,426
Messaggi
506,260
Utenti registrati
111,265
Ultimo utente registrato
Simo03

Staff online

Utenti online

Top