Custom design check - layers

Programming and macros
User avatar
the_h4mmer
Posts: 136
Joined: Mon Jan 31, 2022 6:49 am
Answers: 1
x 106
x 80

Custom design check - layers

Unread post by the_h4mmer »

I haven't dove into it too deeply yet, but was wondering if anyone has an idea or could point me to a resource for building a custom macro for running during Design Checker. As part of our review process, we're trying to ensure that drawing annotations, dimensions, revision markers, tables, etc. are placed on the proper layers (particularly when updating old drawings, new drawings have this done automatically per a new drafting standard).

So far, I've found the codestack macro for moving all selected items to a specific layer as well as the API examples for Get All Notes in drawing template and Get Layers. These certainly are good references, but I haven't been able to synthesize anything from them so far. Wondering if anyone else has other examples/reference they can point to and/or if anyone has built anything like this?

Speaking of, do many here use the Design Checker tool at all?
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: Custom design check - layers

Unread post by zwei »

If i understand correctly, what you are trying to do is get the layer list and iterate through all drawing item (dimension, table, notes, etc) and compare them with the layer list

Not sure will this help...

Codestack has a macro that iterate through all dimension and export them.
This might be a good starting point.
Instead of exporting the dimension you will read and check (and maybe export) the dimension that do not meet your layer requirement
https://www.codestack.net/solidworks-ap ... imensions/

You can use GetDimensionInfo6 to get the layerID
https://help.solidworks.com/2017/englis ... info6.html

Not sure about design checker (I had been wanting to setup one, but it had been in my backlog for months)
Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
User avatar
the_h4mmer
Posts: 136
Joined: Mon Jan 31, 2022 6:49 am
Answers: 1
x 106
x 80

Re: Custom design check - layers

Unread post by the_h4mmer »

Zhen-Wei Tee wrote: Tue May 03, 2022 8:03 am If i understand correctly, what you are trying to do is get the layer list and iterate through all drawing item (dimension, table, notes, etc) and compare them with the layer list

Not sure will this help...

Codestack has a macro that iterate through all dimension and export them.
This might be a good starting point.
Instead of exporting the dimension you will read and check (and maybe export) the dimension that do not meet your layer requirement
https://www.codestack.net/solidworks-ap ... imensions/

You can use GetDimensionInfo6 to get the layerID
https://help.solidworks.com/2017/englis ... info6.html
Thanks for pointing me to these! Definitely seem like they'll be helpful for what I'm looking to do.
Zhen-Wei Tee wrote: Tue May 03, 2022 8:03 am Not sure about design checker (I had been wanting to setup one, but it had been in my backlog for months)
Design checker doesn't take all that long to setup, but when collaborating (or even working solo) it's a great tool to make sure that design documents conform to whatever standards are in place. I have one setup for our company that is used for assemblies, parts, and drawings; checking:

* correct drafting standard is used
* correct sheet format is used(although there seems to be a capitalization bug)
* runs spell check
* verify units and precision
* look for custom property values or presence
* find missing balloons for BOM items
* look for undefined sketches
* find dangling dimensions
* and a lot more!

When it comes to checking designs and/or updating old designs, it's the first thing I do, it basically gives me a list of what's wrong or what needs to be fixed (it even gives me an option to change settings with a single button).
User avatar
gupta9665
Posts: 420
Joined: Thu Mar 11, 2021 10:20 am
Answers: 25
Location: India
x 438
x 459

Re: Custom design check - layers

Unread post by gupta9665 »

Look at the macros in this post viewtopic.php?t=1538

The macros posted here might not be same as you need but can guide you in a direction.
Deepak Gupta
SOLIDWORKS Consultant/Blogger
User avatar
loeb
Posts: 70
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Re: Custom design check - layers

Unread post by loeb »

Hammer,

I recently ran into a limitation that I think will be a problem for you too. I don't think that there's a way to identify if a note is a revision symbol. I wanted to make a macro that finds and changes the color of all revision symbols that might be left over from previous revisions, but couldn't find any way to find/select them using VBA (2021).

If you can't identify revision symbols, you can't identify what layer they're on. If anyone know a way around this limitation, i'd love to know.
User avatar
zwei
Posts: 701
Joined: Mon Mar 15, 2021 9:17 pm
Answers: 18
Location: Malaysia
x 185
x 600

Re: Custom design check - layers

Unread post by zwei »

loebotomy@gmail.com wrote: Sat May 07, 2022 7:48 pm Hammer,

I recently ran into a limitation that I think will be a problem for you too. I don't think that there's a way to identify if a note is a revision symbol. I wanted to make a macro that finds and changes the color of all revision symbols that might be left over from previous revisions, but couldn't find any way to find/select them using VBA (2021).

If you can't identify revision symbols, you can't identify what layer they're on. If anyone know a way around this limitation, i'd love to know.
Not sure will this help...
This is a example of identifying and delete the rev triangle note
The note is identify by using any single character note with a triangle border
Credit to Leonard K

Code: Select all

Attribute VB_Name = "DelRevTriangles1"
'--------------------------------------------------------------------05/27/2003
' DelRevTriangles.swp - Copyright 2003 Leonard Kikstra
'------------------------------------------------------------------------------
Dim swApp As Object
Dim Document As Object
Dim SelectEntity As Object
' SolidWorks constants
Const swDocPART = 1
Const swDocASSEMBLY = 2
Const swDocDRAWING = 3
Const swBS_None = 0
Const swBS_Circular = 1
Const swBS_Triangle = 2
Const swBS_Hexagon = 3
Const swBS_Box = 4
Const swBS_Diamond = 5
Const swBS_SplitCirc = 6
Const swBS_Pentagon = 7
Const swBS_FlagPentagon = 8
Const swBS_FlagTriangle = 9
Const swBS_Underline = 10
Const swCThread = 1
Const swDatumTag = 2
Const swDatumTargetSym = 3
Const swDisplayDimension = 4
Const swGTol = 5
Const swNote = 6
Const swSFSymbol = 7
Const swWeldSymbol = 8
Const swCustomSymbol = 9
Const swDowelSym = 10
Const swLeader = 11
Const swBlock = 12
Const swCenterMarkSym = 13
Const swTableAnnotation = 14

'------------------------------------------------------------------------------
' Delete revision triangles from SolidWorks drawings.  As written, a revision
' triangle is identfied as any single character note with a triangle border.
'------------------------------------------------------------------------------
Sub Main()
  Set swApp = CreateObject("SldWorks.Application")         ' Attach to SWX
  Set Document = swApp.ActiveDoc                           ' Grab active doc
  If Document Is Nothing Then                              ' Is doc loaded
    MsgBox "No model loaded."                              ' Nothing - Warn
  Else                                                     ' Doc loaded"
    FileTyp = Document.GetType                             ' Get doc type
    If FileTyp = swDocDRAWING Then                         ' Is doc drawing ?
      SheetNames = Document.GetSheetNames                  ' Get sheet names
      DelCount = 0                                         ' Reset counter
      For i = 0 To Document.GetSheetCount - 1              ' For each sheet
        Document.ActivateSheet (SheetNames(i))             ' Activate sheet
        Set view = Document.GetFirstView                   ' Get first view
        While Not view Is Nothing                          ' View is valid
          Set Annotation = view.GetFirstAnnotation2        ' Get first annot
          While Not Annotation Is Nothing                  ' Annot valid?
            If Annotation.GetType = swNote Then            ' Note annotations
              Set NOTE = Annotation.GetSpecificAnnotation  ' Get specific note
              If NOTE.GetBalloonStyle = swBS_Triangle Then ' Triangle = Rev
                NoteVal = NOTE.GetText                     ' Get next note
                If Len(NoteVal) = 1 Then                   ' Single character
                  Annotation.Select2 True, 0               ' Add selection set
                  DelCount = DelCount + 1                  ' Inc del counter
                End If                                     ' Single char check
              End If                                       ' Triangle border?
            End If                                         ' Note annotation
            Set Annotation = Annotation.GetNext2           ' Next annotation
          Wend                                             ' Annotation valid
          Document.DeleteSelection False                   ' Delete selection
          Set view = view.GetNextView                      ' Get next view
        Wend                                               ' View is valid
      Next i                                               ' Next sheet
      If i > 0 Then                                        ' More than 1 sheet
        Document.ActivateSheet (SheetNames(0))             ' back to 1st sheet
      End If                                               ' More than 1 sheet
      MsgBox Str(DelCount) + " revision triangles deleted" ' Display status
    End If                                                 ' Check doc type
  End If                                                   ' Check doc loaded
End Sub

Far too many items in the world are designed, constructed and foisted upon us with no understanding-or even care-for how we will use them.
User avatar
AlexB
Posts: 508
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 29
x 274
x 462

Re: Custom design check - layers

Unread post by AlexB »

loebotomy@gmail.com wrote: Sat May 07, 2022 7:48 pm Hammer,

I recently ran into a limitation that I think will be a problem for you too. I don't think that there's a way to identify if a note is a revision symbol. I wanted to make a macro that finds and changes the color of all revision symbols that might be left over from previous revisions, but couldn't find any way to find/select them using VBA (2021).

If you can't identify revision symbols, you can't identify what layer they're on. If anyone know a way around this limitation, i'd love to know.
Not sure it helps in this case specifically, but it is possible to get the revision symbols. Although, I'm not sure there's a way to view that through the INote interface or IAnnotation interface. I had to use the RevisionTableAnnotation object to go row by row and call the following statement:

Code: Select all

revSymbols = swRevTable.GetRevisionSymbols(row)
User avatar
loeb
Posts: 70
Joined: Sun Jan 16, 2022 5:55 pm
Answers: 1
x 39
x 10

Re: Custom design check - layers

Unread post by loeb »

Zhen-Wei Tee,
That idea will work well for use because we use a unique revision table symbol (circle square) which is a headache since that's not a valid default symbol, so we have to manually change the symbol from one of the default options, but in this case, it will work in our favor since that symbol is rarely use anywhere else.
Post Reply