Results 1 to 9 of 9

Thread: Programmatically change block’s visibility parameter when an attribute is changed.

  1. #1
    Member
    Join Date
    2013-07
    Posts
    4
    Login to Give a bone
    0

    Unhappy Programmatically change block’s visibility parameter when an attribute is changed.

    Hi I am new here and have a little problem.

    Ihave an AutoCAD dynamic block, it has a few attributes and a visibilityparameter that allows different switches to be displayed as part of the block.This block is used as part of a template that is used with a database softwarepackage. SQL queries are written in the block’s attributes, when the templateis selected from the database software the template is automatically populatedwith the information.

    TheSQL queries can only be written in the blocks attributes. I can add anotherattribute to the block and insert a SQL query to index to the correctvisibility number to show the right switch. What I need is aVBA routine to sense a change in and attribute and then changing the valueof the visibility parameter so the correct switch is displayed.

    I am not very familiar with the AutoCAD methods, properties and events, juststarted researching this week, in fact.

  2. #2
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    Quote Originally Posted by avanzandt398157 View Post
    What I need is aVBA routine to sense a change in and attribute and then change the value of the visibility parameter so the correct switch is displayed.
    How are you changing the attribute using your SQL database? The moment your attribute is updated by the SQL database is the moment you can change the setting of your visibility parameter for that block. If the value of the change caused by the SQL determines which visibility state is activated, I'd use "Select case".

  3. #3
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,535
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    Welcome to AUGI, and congrats on your first post!

    How did you get along with the suggestions made in your duplicate thread?

    Cheers
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  4. #4
    Member
    Join Date
    2013-07
    Posts
    4
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    I haven't had any sucess for a resolution. It seams there is a dll the Aveva program uses to run an external program that changes the attributes of the blocks as per the SQL query defined in the attribute. I have tried to make some code to look at the attributes but not any sucess. Right now I'm busy with some other things, but, this will come back again. Any thoughts of where to start?

    Thanks

  5. #5
    Administrator BlackBox's Avatar
    Join Date
    2009-11
    Posts
    5,535
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    Quote Originally Posted by avanzandt398157 View Post
    ... Any thoughts of where to start?
    Same as before....

    Using .NET API... You need to hook the ObjectModified event to store applicable ObjectId's (filtering for ObjectId.ObjectClass.Name == "AcDbAttributeReference", and any applicable Tag string, etc.), as one cannot modify an Object that is opened in the Database, and since there is no CommandMethod being called (which means there are no CommandCancelled, CommandEnded, nor CommandFailed events raised), you're relegated to using an ObjectOverrule to process the stored ObjectId's... Subsequently using a Transaction to obtain the parent Dynamic Block by the DBObject Type-cast Object's OwnerId for your ObjectId's, in order to further open the BlockReference and obtain its DynamicBlockReferencePropertyCollection Object.
    Last edited by BlackBox; 2013-07-31 at 04:35 AM.
    "How we think determines what we do, and what we do determines what we get."

    Sincpac C3D ~ Autodesk Exchange Apps

    Computer Specs:
    Dell Precision 3620, Core i7-7700K 4.2GHz, 64GB RAM, Samsung 970 Pro M.2, 8GB NVIDIA Quadro P4000

  6. #6
    AUGI Addict
    Join Date
    2015-12
    Posts
    2,095
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    Careful with all this. AVEVA P&ID (yes?) does quite a few operations with the SQL database and if you don't account for everything its easy to get the DWGs and database out of synch.
    If you are going to fly by the seat of your pants, expect friction burns.
    Some say beauty is in the eye of the Beholder... perhaps so, but I've only seen the disintegration beam.
    Everyone else being wrong is not the same thing as being right.

  7. #7
    Member
    Join Date
    2013-07
    Posts
    4
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    I am using Aveva Instrument. It is another part of their software suite, I think they all operate about the same. I am trying to get the visibility parameter of a dynamic block to change after Aveva has updated the data in an attribute.

  8. #8
    100 Club
    Join Date
    2007-07
    Posts
    104
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    Perhaps you could read in the values of the original block / template. Then after the template has been used and the attributes have changed, you read their new values and compare them to the original values. If they've changed, the visibility parameter must change.
    Last edited by CADfunk MC; 2013-07-31 at 12:39 PM.

  9. #9
    Member
    Join Date
    2013-07
    Posts
    4
    Login to Give a bone
    0

    Default Re: Programmatically change block’s visibility parameter when an attribute is changed.

    Well… I found a way to do what I wanted. It may not be a eloquent as a seasoned pro but, hey, it works.
    I have the following code in the ThisDrawing.
    Public LastID As Variant
    Dim NoRun As Boolean

    Code:
    Private Sub AcadDocument_BeginCommand(ByVal CommandName As String)
        NoRun = True
    End Sub
    
    Private Sub AcadDocument_EndCommand(ByVal CommandName As String)
        NoRun = False
    End Sub
    
    Private Sub AcadDocument_BeginSave(ByVal FileName As String)
        NoRun = True
    End Sub
    
    Private Sub AcadDocument_EndSave(ByVal FileName As String)
        NoRun = False
    End Sub
    
    Private Sub AcadDocument_ObjectModified(ByVal Object As Object)
    If NoRun Then Exit Sub ' if there are othere activities do not call Sub
    
        ' If the Modified Object is a dynamic block then call the Sub
        If Object.ObjectName = "AcDbAttribute" And LastID <> Object.OwnerID32 Then
            ' Save the Owner ID so the Sub is only called once for the Block Modification
            LastID = Object.OwnerID32
            Call ModifiedObject(Object, LastID)
        End If
    End Sub
    From the ObjectModified event it will call a Sub in Module1.

    Code:
    Option Explicit
    
    Public Sub ModifiedObject(ByVal Object As Object, LastID As Variant)
    
        Dim ParObj As AcadObject
        Dim obj As AcadObject
        Dim BlkRef As AcadBlockReference
        Dim varAttributes As Variant
        Dim DBRP As Variant
    
        Set obj = Object
        Set ParObj = ThisDrawing.ObjectIdToObject32(obj.OwnerID32)
        
        ' Check the object's parent type (Dynamic Block Reference)
        If ParObj.EntityName = "AcDbBlockReference" Then
        
            ' change object type to get Block Reference Attributes
            ' and test for the correct Dynamic Block Name
            Set BlkRef = ParObj
            If BlkRef.EffectiveName = "SW_INPUT" Then
            
                ' Get the attributes for the block reference
                varAttributes = BlkRef.GetAttributes
                
                ' If the Instrument Tag attribute hasn't changed leave the sub
                If varAttributes(0).TextString = "INSTRUMENT_TAG" Then
                    Set obj = Nothing
                    Set ParObj = Nothing
                    Set BlkRef = Nothing
                    LastID = ""
                    Exit Sub
                End If
                
                varAttributes(4).TextString = ""
                
                ' Set the value of of the dynamic block attribute to
                ' the code for the switch type
                DBRP = BlkRef.GetDynamicBlockProperties
                        
                DBRP(0).Value = GetSwitchType(varAttributes(0).TextString)
                
            End If
        End If
        
        ' Clean up before exiting the Sub
        Set obj = Nothing
        Set ParObj = Nothing
        Set BlkRef = Nothing
    
    End Sub
    
    Private Function GetSwitchType(ByVal TagName As String) As String
    
    Dim RetVal, Fst, Trd, WkStr As String
    
    WkStr = Left(TagName, 3)
    Fst = UCase(Left(WkStr, 1))
    Trd = UCase(Right(WkStr, 1))
    Debug.Print TagName & " = " & Fst & ", " & Trd
    
    Select Case Fst
    
        Case "P" ' Test for a Pressure Switch
            If Trd = "L" Then
                GetSwitchType = "A1"
            Else
                GetSwitchType = "A2"
            End If
        Case "T" ' Test for a Temperature Switch
            If Trd = "L" Then
                GetSwitchType = "B1"
            Else
                GetSwitchType = "B2"
            End If
            
        Case "L" ' Test for a Level Switch
            If Trd = "L" Then
                GetSwitchType = "C1"
            Else
                GetSwitchType = "C2"
            End If
            
        Case "F" ' Test for a Flow Switch
            If Trd = "L" Then
                GetSwitchType = "D1"
            Else
                GetSwitchType = "D2"
            End If
            
        Case "Z" ' Test for a Position Switch
            If Trd = "C" Then
                GetSwitchType = "E1"
            Else
                GetSwitchType = "E2"
            End If
            
        Case Else ' If the type doesn't match anything else use contacts
            If Trd = "L" Then
                GetSwitchType = "F1"
            Else
                GetSwitchType = "F2"
            End If
    End Select
        
    End Function

Similar Threads

  1. 2012: how to tie visibility parameter to attribute?
    By Ning Zhou in forum Dynamic Blocks - Technical
    Replies: 5
    Last Post: 2018-09-20, 01:30 AM
  2. How to change dynamic block attribute default values based on block selected?
    By zeirz109180 in forum Dynamic Blocks - Technical
    Replies: 2
    Last Post: 2013-12-13, 02:20 PM
  3. Replies: 13
    Last Post: 2012-09-18, 07:51 PM
  4. Replies: 5
    Last Post: 2009-09-16, 01:39 AM
  5. Block / Attribute Behavior Changed
    By bob.92091 in forum AutoCAD LT - General
    Replies: 1
    Last Post: 2008-06-26, 02:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •