Donate Now Goal amount for this year: 2500 USD, Received: 1627 USD (65%)

Results 1 to 7 of 7
Like Tree13Likes
  • 4 Post By amoursol
  • 1 Post By cellophane
  • 4 Post By johnp
  • 3 Post By amoursol
  • 1 Post By johnp

Thread: Sharing: Set Above Text Field to Dimensions ( Annotated Python )

  1. #1
    Senior Member amoursol's Avatar
    Join Date
    November 21, 2012
    Location
    London, United Kingdom
    Posts
    612
    Current Local Time
    01:34 PM

    Sharing: Set Above Text Field to Dimensions ( Annotated Python )

    Hello all,

    Just wanted to share a Python node from my upcoming AU London Python for Beginners class in a few weeks. You guys may find it useful!



    Code:
    """
    IMPORTING MANAGERS
    """
    __author__ = 'Sol Amour - sol.amour@designtech.io'
    __twitter__ = '@solamour'
    __copyright__ = 'designtech.io 2018'
    __version__ = '1.0.0'
    
    
    # Importing Reference Modules
    import clr # CLR ( Common Language Runtime Module )
    clr.AddReference("RevitServices") # Adding the RevitServices.dll special Dynamo module to deal with Revit
    import RevitServices # Importing RevitServices
    from RevitServices.Persistence import DocumentManager # From RevitServices import the Document Manager
    from RevitServices.Transactions import TransactionManager # From RevitServices import the Transaction Manager
    
    # Here we give the Revit Document a nickname of 'doc' which allows us to simply call 'doc' later without having to type the long namespace name 
    doc = DocumentManager.Instance.CurrentDBDocument
    
    
    # The input ports 
    dimensions = UnwrapElement(IN[0]) # Here we 'unwrap' our Dynamo objects. Dynamo and Revit Elements are different - Dynamo has wrapped them up in order to manipulate them so for us to use them in the actual Revit Project we need to unwrap them so that we can talk to the Revit API
    text = IN[1] # As this input is simply text we do not need to unwrap it
    
    # Wrapping the body of our code inside of Transactions. This allows us to effect the Revit Project ( Document ).
    TransactionManager.Instance.EnsureInTransaction(doc) # We have to be inside of a Transaction to manipulate the Revit Project so we use the Dynamo Specific transaction wrapper ( A special way to use the Transaction Class ) to ensure we are in a transaction. This way, if anything goes wrong inside of our script the Manager will ensure nothing breaks, that any partial changes made are reverted and that our Revit file is cleaned up before progressing
    
    # We generate an empty catchment list to append (add to) our results
    results = []
    
    # We then run a For Loop across every single element that is coming into our 'dimensions' input node
    for dim in dimensions: # For every single dimension inside of our input list called 'dimensioins', do the following...
        dim.Above = str(text) # Set the property called 'Above' ( Which refers to the Text Field entitled 'Above' inside of the Dimensions editor ) to our chosen text from our second input port
        results.append(dim) # Then simply append ( add ) this dimension to our empty catchment list 'results'
    
    TransactionManager.Instance.TransactionTaskDone() # After we have our script body finish executing, we want to close our Transaction. So we once again use the wrapper to close the Transaction using the 'TransactionTaskDone()' method
    
    # The output port, showcasing the Revit Documents Saved Name
    OUT = results
    Results in Revit:



    It should be pretty easy to set the rest of the options using this
    Attached Thumbnails Attached Thumbnails Sharing: Set Above Text Field to Dimensions ( Annotated Python )-dimensions_dynamo_graph.jpg   Sharing: Set Above Text Field to Dimensions ( Annotated Python )-dynamo_revit_dims.jpg  
    Last edited by amoursol; June 6th, 2018 at 04:56 PM.

  2. #2
    Member d.stairmand's Avatar
    Join Date
    February 24, 2011
    Location
    Auckland
    Posts
    348
    Current Local Time
    12:34 AM
    Sol
    from what i can see - your way adds the above text to all the dims in a dim string?
    Any way to add the Above Text to just say 4 out of 10 dim's in a dim string?

  3. #3
    Moderator cellophane's Avatar
    Join Date
    August 9, 2011
    Location
    Louisville, KY
    Posts
    6,143
    Current Local Time
    08:34 AM
    Quote Originally Posted by d.stairmand View Post
    Sol
    from what i can see - your way adds the above text to all the dims in a dim string?
    Any way to add the Above Text to just say 4 out of 10 dim's in a dim string?
    The Dimension Override tool (part of WorkFlow) that Revolution Design makes can override the entire chain or individual segments. So, in API terms that is possible, just not sure how it would be done in Dynamo.
    johnp likes this.

  4. #4
    Member johnp's Avatar
    Join Date
    March 24, 2015
    Posts
    149
    Current Local Time
    06:34 AM
    You can definitely do that, but it adds a bit more difficulty to it. I added a few things to @Sol's code below.

    Basically, you need to access the individual dimension segements of the multi-segmented dimension. In my case I am doing this by allowing for the user to add which indices the override should happen. (I appended -john, to the lines I added)

    Code:
    """
    IMPORTING MANAGERS
    """
    __author__ = 'Sol Amour - sol.amour@designtech.io'
    __twitter__ = '@solamour'
    __copyright__ = 'designtech.io 2018'
    __version__ = '1.0.0'
    
    
    # Importing Reference Modules
    import clr # CLR ( Common Language Runtime Module )
    clr.AddReference("RevitServices") # Adding the RevitServices.dll special Dynamo module to deal with Revit
    import RevitServices # Importing RevitServices
    from RevitServices.Persistence import DocumentManager # From RevitServices import the Document Manager
    from RevitServices.Transactions import TransactionManager # From RevitServices import the Transaction Manager
    
    # Here we give the Revit Document a nickname of 'doc' which allows us to simply call 'doc' later without having to type the long namespace name 
    doc = DocumentManager.Instance.CurrentDBDocument
    
    
    # The input ports 
    dimensions = UnwrapElement(IN[0]) # Here we 'unwrap' our Dynamo objects. Dynamo and Revit Elements are different - Dynamo has wrapped them up in order to manipulate them so for us to use them in the actual Revit Project we need to unwrap them so that we can talk to the Revit API
    text = IN[1] # As this input is simply text we do not need to unwrap it
    
    indices = IN[2] # allows us to specify which segment to add the value to - john
    
    # Wrapping the body of our code inside of Transactions. This allows us to effect the Revit Project ( Document ).
    TransactionManager.Instance.EnsureInTransaction(doc) # We have to be inside of a Transaction to manipulate the Revit Project so we use the Dynamo Specific transaction wrapper ( A special way to use the Transaction Class ) to ensure we are in a transaction. This way, if anything goes wrong inside of our script the Manager will ensure nothing breaks, that any partial changes made are reverted and that our Revit file is cleaned up before progressing
    
    # We generate an empty catchment list to append (add to) our results
    results = []
    
    # We then run a For Loop across every single element that is coming into our 'dimensions' input node
    for dim in dimensions: # For every single dimension inside of our input list called 'dimensions', do the following...
        for i in indices: # this portion allows you to select the individual pieces of dimension - john
    dim.Segments[i].Above = str(text) # Set the property called 'Above' ( Which refers to the Text Field entitled 'Above' inside of the Dimensions editor ) to our chosen text from our second input port
    results.append(dim) # Then simply append ( add ) this dimension to our empty catchment list 'results'
        
        
    
    TransactionManager.Instance.TransactionTaskDone() # After we have our script body finish executing, we want to close our Transaction. So we once again use the wrapper to close the Transaction using the 'TransactionTaskDone()' method
    
    # The output port, showcasing the Revit Documents Saved Name
    OUT = results
    And the result
    Attached Thumbnails Attached Thumbnails Sharing: Set Above Text Field to Dimensions ( Annotated Python )-2018-06-07_7-57-09.png  
    Last edited by johnp; June 7th, 2018 at 01:57 PM.

  5. #5
    Senior Member amoursol's Avatar
    Join Date
    November 21, 2012
    Location
    London, United Kingdom
    Posts
    612
    Current Local Time
    01:34 PM
    Quote Originally Posted by d.stairmand View Post
    Sol
    from what i can see - your way adds the above text to all the dims in a dim string?
    Any way to add the Above Text to just say 4 out of 10 dim's in a dim string?
    Totally possible as per John's reply above - mine was to be a simple (First point of contact) look at the Revit API through Python for an AU Class

    As a side note, I should have pushed this into my post as well for the winky-face...



    Code:
    if isinstance( IN[0], list):
        ele = UnwrapElement(IN[0])[0]
    else:
        ele = UnwrapElement(IN[0])
    
    OUT = dir(ele)
    This allows you to look at stuff you select and 'Snoop' it - as you can see in the Watch node there is a 'Segments' bit.

    To look at this elements segements, simply change the Python to this

    Code:
    if isinstance( IN[0], list):
        ele = UnwrapElement(IN[0])[0]
    else:
        ele = UnwrapElement(IN[0])
    
    OUT = dir(ele.Segments)
    And you will see that you can do stuff to the Segments too!
    Attached Thumbnails Attached Thumbnails Sharing: Set Above Text Field to Dimensions ( Annotated Python )-directory_python.jpg  
    Last edited by amoursol; June 7th, 2018 at 05:40 PM.
    cellophane, johnp and Ning Zhou like this.

  6. #6
    Member johnp's Avatar
    Join Date
    March 24, 2015
    Posts
    149
    Current Local Time
    06:34 AM
    Quote Originally Posted by amoursol View Post
    Totally possible as per John's reply above - mine was to be a simple (First point of contact) look at the Revit API through Python for an AU Class
    For sure! I would definitely not consider dealing with multi-segment dimensions a beginner thing. They are a pain to deal with.
    amoursol likes this.

  7. #7
    Senior Member amoursol's Avatar
    Join Date
    November 21, 2012
    Location
    London, United Kingdom
    Posts
    612
    Current Local Time
    01:34 PM
    Quote Originally Posted by johnp View Post
    For sure! I would definitely not consider dealing with multi-segment dimensions a beginner thing. They are a pain to deal with.
    As a side note, this did provide the perfect opportunity to showcase error catching So I amended my code (Thanks for the inspiration @johnp and query @d.stairmand) to capture both cases.

    Code:
    """
    IMPORTING MANAGERS
    """
    __author__ = 'Sol Amour - sol.amour@designtech.io'
    __twitter__ = '@solamour'
    __copyright__ = 'designtech.io 2018'
    __version__ = '1.0.0'
    
    
    # Importing Reference Modules
    import clr # CLR ( Common Language Runtime Module )
    clr.AddReference("RevitServices") # Adding the RevitServices.dll special Dynamo module to deal with Revit
    import RevitServices # Importing RevitServices
    from RevitServices.Persistence import DocumentManager # From RevitServices import the Document Manager
    from RevitServices.Transactions import TransactionManager # From RevitServices import the Transaction Manager
    
    # Here we give the Revit Document a nickname of 'doc' which allows us to simply call 'doc' later without having to type the long namespace name 
    doc = DocumentManager.Instance.CurrentDBDocument
    
    
    # The input ports 
    dimensions = UnwrapElement(IN[0]) # Here we 'unwrap' our Dynamo objects. Dynamo and Revit Elements are different - Dynamo has wrapped them up in order to manipulate them so for us to use them in the actual Revit Project we need to unwrap them so that we can talk to the Revit API
    text = IN[1] # As this input is simply text we do not need to unwrap it
    
    # Wrapping the body of our code inside of Transactions. This allows us to effect the Revit Project ( Document ).
    TransactionManager.Instance.EnsureInTransaction(doc) # We have to be inside of a Transaction to manipulate the Revit Project so we use the Dynamo Specific transaction wrapper ( A special way to use the Transaction Class ) to ensure we are in a transaction. This way, if anything goes wrong inside of our script the Manager will ensure nothing breaks, that any partial changes made are reverted and that our Revit file is cleaned up before progressing
    
    # We generate an empty catchment list to append (add to) our results
    results = []
    
    # We then run a For Loop across every single element that is coming into our 'dimensions' input node
    for dim in dimensions: # For every single dimension inside of our input list called 'dimensioins', do the following...
        numOfSegs = dim.NumberOfSegments # Count the amount of Segments the Dimensions has
        if numOfSegs > 0: # Run an 'If' conditional check to see if it has more than zero (Which in turn means it's Segmented). If the answer to this check is True (It's either True or False) then do the following...
            for num in range(numOfSegs): # Create a Number Range starting at zero and ranging to the total count of our Number of Segments
                dim.Segments[num].Above = str(text) # Then for every segmented Dimension, change each Segments 'Above' property ( Which refers to the Text Field entitled 'Above inside of the Dimensions editor ), at each index ( Supplied by our variable num ), to our chosen Text value from our Input port
                results.append(dim) # Then simply append ( add ) this dimension to our empty catchment list 'results'
        else:
            dim.Above = str(text) # Set the property called 'Above' ( Which refers to the Text Field entitled 'Above' inside of the Dimensions editor ) to our chosen text from our second input port
            results.append(dim) # Then simply append ( add ) this dimension to our empty catchment list 'results'
    
    TransactionManager.Instance.TransactionTaskDone() # After we have our script body finish executing, we want to close our Transaction. So we once again use the wrapper to close the Transaction using the 'TransactionTaskDone()' method
    
    # The output port, showcasing the Revit Documents Saved Name
    OUT = results

Similar Threads

  1. Replies: 8
    Last Post: April 30th, 2018, 05:00 PM
  2. Dimensions: Text outside
    By doni49 in forum Architecture and General Revit Questions
    Replies: 6
    Last Post: August 27th, 2015, 09:20 PM
  3. Problems in exporting text and dimensions in dwg
    By marcomella in forum Architecture and General Revit Questions
    Replies: 4
    Last Post: August 19th, 2015, 06:18 PM
  4. Add text under dimensions through API
    By alexo4141 in forum Third party Add-Ins, API and R&D
    Replies: 2
    Last Post: September 27th, 2012, 02:23 PM
  5. Blank Text Field in Wall Tag
    By Chadwick17 in forum Architecture - Family Creation
    Replies: 4
    Last Post: July 23rd, 2012, 05:13 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
  •