HideByAttribute - CAMCAD Automation

Discussion created by chris_czernel on Sep 15, 2009

CAMCAD offers options to color components by attribute - but what if you want something hidden from view, and not just colored? There is a menu command View > Hide Data, which can either hide "top level" items or remove hiding, but this does not allow a user to specify what is to be hidden and only scratches the surface of the hide capabilities of CAMCAD.


This small Visual Basic 6 utility uses the CAMCAD HideData API in the useful context of hiding based on a match to an attribute keyword & value.


ScreenHunter_01 Sep. 15 09.13.gif


The code is very short and should be easy to incorporate this concept into more elaborate scripts. The code is copied below and the full project is in the zip file.







Public objCAMCAD As CAMCAD.Application
Option Explicit


Private Sub cmdHide_Click()

Dim x As Integer
Dim y As Integer
Dim lPosition As Long
Dim bOnOff As Boolean
Dim strName As String
Dim intNumber As Integer, intMirror As Integer, intType As Integer, intGeomNum As Integer
Dim sglScale As Single, sglx As Single, sglY As Single, sglAngle As Single
Dim placementArray As Variant
Dim tempArray As Variant
Dim bVisible As Boolean


    ' make sure values are set in the text boxes
    If Text1.Text = "Attribute Name" Or Text2.Text = "Attribute Value" Then
        MsgBox "Please enter an attribute name and value to hide or show."
        Exit Sub
    End If
    ' get the active file position number
    objCAMCAD.GetActiveFile lPosition
    ' now get data for this active file, to get the intGeomNum geometry number (needed later for the hide)
    objCAMCAD.GetFile2 lPosition, strName, intNumber, bOnOff, sglx, sglY, sglScale, sglAngle, intMirror, intType, intGeomNum
    ' use the GetPlacementData2 function as it returns both component data positions as well as attributes in PlacementArray
    objCAMCAD.GetPlacementData2 lPosition, 3, placementArray
    ' loop through the placement array, parse it, and look for the attribute name and value
    For x = 0 To UBound(placementArray)
       tempArray = Split(placementArray(x), Chr(5))
       For y = 0 To UBound(tempArray)
            If tempArray(y) = Text1.Text Then
                If tempArray(y + 1) = Text2.Text Then ' this means the attribute and value were found in the data line, so take action on this component
                ' do this
                        If optHide(1).Value = True Then ' setup a boolean to store whether the option is set to hide or show
                        bVisible = False
                        bVisible = True
                        End If
                        ' now hide or show the part!
                        objCAMCAD.HideData intGeomNum, tempArray(11), bVisible
                        Exit For
                End If
            End If
       Next y
    Next x
   ' tell CAMCAD to redraw
End Sub


Private Sub Form_Load()
Set objCAMCAD = New CAMCAD.Application


End Sub