Showing posts with label VBScript. Show all posts
Showing posts with label VBScript. Show all posts

December 12, 2013

ACA: Formula Property to Determine if a Block Instance is a Dynamic Block

You can use the following code in an AutoCAD® Architecture Formula Property in a Property Set that applies to Block References to determine if the Block Reference is a Dynamic Block.
set acadApp = GetObject(,"AutoCAD.Application")
set obj = acadApp.ActiveDocument.ObjectIDToObject( [ObjectID] )
RESULT = obj.IsDynamicBlock

As in the previous example, [ObjectID] is a properly created property reference to an automatic property in the same Property Set, named ObjectID, which references the Object ID automatic property source. This formula will return a value of TRUE if the block reference is a Dynamic Block and FALSE if the block is a "regular" block. The property can be used as the condition for an IF Statement, if you need another Formula property to take different actions based on whether or not the block reference is a dynamic block.

December 10, 2013

ACA: Obtaining the Effective Name of a Dynamic Block in a Formula Property

While Dynamic Blocks and ACA do not always play nicely, there are some who want to take advantage of both Dynamic Blocks and the AutoCAD® Architecture Schedule feature. One challenge is that the Name automatic property source may return an anonymous block name rather than the Dynamic Block name; for example, when a Dynamic Block with a stretch action is stretched. Fortunately, you can obtain the orignal block name from the EffectiveName property of the Dynamic Block instance, in a Formula property, using the the following VBScript code:
set acadApp = GetObject(,"AutoCAD.Application")
set obj = acadApp.ActiveDocument.ObjectIDToObject( [ObjectID] )
RESULT = obj.EffectiveName

The Property Set Definition that includes the Formula property will also need to have a property that references the Object ID automatic property source. In the example code above, this property has the default ObjectID name, and the [ObjectID] text in the formula represents a properly created property reference, created by double-clicking the property name in the Insert Property Definitions box in the lower left of the Formula Property Definition dialog.

February 12, 2012

ACA: Extracting Text from a Style Name

In a recent reply post in the Getting steel beam size thread in the Autodesk AutoCAD® Architecture Discussion Group, Dallas asked if there was a way to automatically extract a value embedded in the name of a Structural Member Style. The specific example was if the style name were to include the shape size followed by the depth in parentheses: W16x45 (16.13).

I replied with a file attachment that had a sample file demonstrating that this was possible. The style-based StrMembStyles01 Property Set Definition, which applies to Structural Member Styles, in that file contains an Automatic property called Style that uses the Style automatic property source to make the style name available. The MemberDepth property uses the following VBScript code to extract the value between the parentheses in the style name and convert it to a real number:
styleName = "[Style]"
startChar = InStr( "[Style]",  "(" ) +1
endChar = InStr(  "[Style]",  ")" )
strLen = endChar - startChar

If strLen <= 0 Then
 memberDepth = 0
Else
 memberDepth =  Mid( styleName, startChar, strLen )
End If

If Not IsNumeric( memberDepth ) Then
 memberDepth = 0
End If

RESULT = CDbl(memberDepth)
Notes:
  1. The first line assigns the text string in the [Style] property to the variable styleName. As always, you cannot simply type or paste a property reference in a formula property. You have to insert them by placing your cursor in the upper left edit box and then double click the property in the list in the lower left box.
  2. The second line uses the VBScript InStr function to determine the position of the first character of the depth value embedded in the style name, which is presumed to be the first character after the first open parenthesis character, "(", found in the string. This is saved in the variable startChar.
  3. The third line also uses the InStr function to save the position of the first close parenthesis character, ")", to the variable endChar. In both the second and third lines, I probably should have used the styleName variable in lieu of additional references to the [Style] property.
  4. The fourth line assigns difference between startChar and endChar to the variable strLen, which is the length of the string that gives the member depth. Using the InStr function with delimiter characters avoids the need to have a fixed number of characters before the depth value and a fixed number of characters for the depth. The only requirement is that the first "(" character in the name immediately precede the depth value, and the first ")" character immediately follow the depth value.
  5. At this point, we have all of the information we need to get the string representing the member depth. If the Property Set gets attached to a Structural Member Style whose name is not properly formatted (no parentheses, first "(" is either preceded by or immediately followed by the first ")", one or more non-numeric characters between the first "(" and ")") and the resultant string is converted to a double precision number, an error will result. The formula property is set up to return a depth of 0 for improperly formatted style names. All of the mentioned error conditions except for non-numeric characters will result in a string length of 0 or less. The first If statement checks for this condition and sets variable memberDepth to 0 if true; otherwise it extracts the string between the first "(" and first ")".
  6. The second If statement tests the extracted string to verify it either is numeric or is a string that can be evaluated as numeric using the IsNumeric function, preceded by the Not operator. If the extracted string is not numeric, the value of memberDepth is reset to 0, otherwise, it is left as is.
  7. At this point, the value of memberDepth is either 0 or a numeric string, and can be converted to a double precision real number using the CDbl function. It is up to whatever additional use you make of this property to determine how to handle a value of 0.
Download the sample file attached to my post to see this formula property in action.

January 09, 2007

Formula Property VBScript Help

It has just dawned on me that I have never published a link to the Microsoft Developer Network VBScript page, from which you can drill down and find all sorts of help on the syntax for VBScript commands. [Click on the image for a larger view.]

Note also that users of ADT 2006 and 2007 can access the help for a specific command "directly" when writing a formula by finding the command in the lower right pane, right clicking on the command and choosing VBScript Help: from the context menu.

August 13, 2006

ADT Schedule Feature Resources

Here are some links to various resources that can help you understand the Scheduling Feature of ADT/ACD-A. Some are from some time back, so the specifics for more current releases may be slightly different, but all have something to offer. Do not forget to check out the ADT/ACD-A Help, too.

Brain Dumps 13, Schedule Basics and 15, Creating Schedule Tags, by Matt Dillon
Grab these from Chris Yanchar's Between the Walls ADT Weblog
or go to the original threads that were the basis of the Brain Dumps:
Brain Dump 13, Schedule Basics
Brain Dump 15, Creating Schedule Tags
9/1/2008 Update: The links to the Brain Dumps in Chris' blog appear to be dead, so you will have to go to the original threads.

Brain Dump 13, Schedule Basics, updated for ADT 2006
This is an update of Matt Dillon's classic, based on ADT 2006 means and methods.

Property Data Enhancements, by Scott Arvin
This "must read" covers the "new" property types that were added in ADT 2004, including formula properties.

NOTE: AUGI now has "levels" of membership, and access to the AUGI Training Program (ATP) materials is not part of the free membership level. In order to have access to the ATP materials noted below, you will have to join at one of the paid levels.

ATP071 Schedule Basics Course Materials, by David Koch
If you are a member of AUGI [its free], you have access to archived AUGI Training Program course materials. Download the materials for ATP071, which can be found by logging into the AUGI website and, from the Home page, clicking on the following links:
Education > AUGI Training Program > Archived ATP Courses
Scroll down to April, 2005 and download the course materials for ATP071. Then visit the archived Course Forum [click on the link] and look for the "Formula Property Exercise" thread. Download the supplemental exercise on formula properties that is attached to my first post in that thread.

Not an AUGI member yet? Sign up here.

ATP121 ADT Formula Properties Course Materials, by David Koch
This course was offered in June, 2006, and is also available in the ATP Archives.

Autodesk University 2007 - AB114-4 Get Fully Equipped in AutoCAD® Architecture Session Materials
Details on how to access the session handout and sample files can be found in this blog article.

Here are some previous articles in my blog, related to the Schedule Feature, that you may have missed:
11/25/2004 - Autodesk Architectural Desktop Tags
12/21/2004 - Overriding A Property Value Using A Formula
12/22/2004 - Clustering Spaces Within a Unit in a Space Schedule
12/24/2004 - Electrical Device Schedule Using Clustering
01/12/2005 - "Unformatted" Properties for Formulas
01/29/2005 - VBScript Operators for Formula Properties
03/21/2005 - ADT 2006 Tags Illustrated
04/03/2005 - Formula Property Interface Improved in ADT 2006
04/19/2005 - Scale-Dependent Tags in ADT
07/03/2005 - Structure/Flow in Formula Properties: If/Then/ElseIf/Else Construct
07/04/2005 - Multi-Line Room Name Formula Improvements
07/09/2005 - Multi-Line Room Name Formula Revisited
07/09/2005 - Structure/Flow in Formula Properties: Select Case Construct
07/16/2005 - Unformatted Properties and Numeric Precision
07/16/2005 - WxH Formula For Windows
08/03/2005 - Schedule Column Loss in "Old" Drawings
08/31/2005 - Rounding Up Property Data Values
08/31/2005 - Rounding Revisited
09/03/2005 - Rounding Redux
09/15/2005 - Rounding to Death
09/24/2005 - Scale-Dependent Tag Tools in ADT 2006
11/02/2005 - Filtering Objects in an ADT Schedule
11/14/2005 - Dealing with NA in Formulas
12/13/2005 - Sorting Schedules by Door Numbers with Suffixes
12/20/2005 - Underline in Tag But Not in Schedule
12/24/2005 - Schedule Table Placeholders
12/28/2005 - Schedule Basics Brain Dump for 2006
01/04/2006 - Residential Door Tags
01/12/2006 - Sorting Character Strings Like Numbers
01/14/2006 - Sorting Character Strings Like Numbers Image
01/14/2006 - Richard Binning: Auto Tagging With VBA
01/15/2006 - Door/Window Assembly Frame Depth in Window Schedule
01/25/2006 - Using System Variable Values in Formula Properties
01/28/2006 - Formatting Areas and Volumes in Schedules Using Drawing Setup
02/03/2006 - Underline in Tag But Not in Schedule II
03/11/2006 - Enhanced Property Data Features in ADT 2007, Part 1 [visibility and order]
03/21/2006 - Enhanced Property Data Features in ADT 2007, Part 2 [anchor and graphic properties]
03/24/2006 - Enhanced Property Data Features in ADT 2007, Part 3 [unit type]
03/31/2006 - Enhanced Property Data Features in ADT 2007, Part 4 [list definition]
04/08/2006 - Enhanced Property Data Features in ADT 2007, Part 5 [table title and header overrides; formula columns]
04/27/2006 - Stacking Properties in a Schedule Table
05/01/2006 - Using Property Data Formats to Force Real Number Interpretation
05/04/2006 - Retrieving the Door Type of a Door Style
05/23/2006 - Retrieving the Door Type of a Door Style 2
06/10/2006 - Tag for Polyline-based "Rooms"
06/17/2006 - Separating Structural Shape Names in a Complex Structural Member Style
06/24/2006 - Automatically Displaying a Viewport’s Scale
07/29/2006 - Room Name/Number PSD Heads Up in 2007
09/03/2006 - NA in Formulas Revisited
09/09/2006 - List Definitions and Multi-Line Room Names
01/09/2007 - Formula Property VBScript Help
01/10/2007 - List Definitions - Utility to Import/Export
01/20/2007 - Scale-Dependent Schedule Tags in ADT 2006 or 2007
02/16/2007 - Dealing "*Xxx not found*" Location Property Result
03/03/2007 - Adding a New Scale to a Scale-Dependent Block
03/20/2007 - Another Formula Property Override Example
04/01/2007 - ADT 2006 & Prior - Angular Automatic Properties
04/06/2007 - Annotative Tags With Leaders in ACA 2008
04/10/2007 - Multiple-Line Room Tags
04/15/2007 - ACA 2008/ADT 2007: Setting a Different Property Data Format in a Formula Property
04/26/2007 - Revising a Schedule Table Style
06/16/2007 - AU 2007
06/16/2007 - Rounded Values and the Quantity Column
07/01/2007 - Anchor Property Sample
07/25/2007 - Pasting Formulas
12/24/2007 - AB114-4 Class Materials and Webcast
05/01/2008 - Property Set Tools
06/16/2008 - Text Case and the Quantity Column
07/28/2008 - Copy/Paste and Formulas
09/15/2008 - On Error Resume Next
09/16/2008 - Z-Coordinates of Aec Objects
10/27/2008 - Zoom To from Schedule Table Fails
11/15/2008 - Creating Annotative Tags in AutoCAD Architecture
12/19/2008 - Non-Project Door Tag Using Room Number with Prefix and/or Suffix
04/10/2009 - Deleting Property Sets Using the Properties Palette
06/12/2009 - Copying a Schedule Table Between Drawings
08/28/2009 - Another Automatic Property Override Sample
11/25/2009 - ACA Scheduling by "Mark"
12/29/2009 - Space Schedule with Header Rows, sorted by Level and Building/Wing
11/25/2011 - Rounding and Column Totals
02/12/2012 - ACA: Extracting Text from a Style Name
03/27/2012 - ACA 2013 - Grouping and Subtotals in Schedule Tables
06/24/2012 - ACA: Occupancy Load Calculations and Division by Zero
06/26/2012 - ACA: Occupancy Load Calculations with a Column Total
03/26/2013 - ACA 2014: Property Set Defintion Auto-attach
12/10/2013 - ACA: Obtaining the Effective Name of a Dynamic Block in a Formula Property
12/12/2013 - ACA: Formula Property to Determine if a Block Instance is a Dynamic Block
02/12/2014 - ACA: Double Click a Tag to Edit Property Data
05/26/2015 - ACA/AMEP 2016: Property Visibility Override
06/29/2015 - ACA: Classification Definitions, Applies To and Tagging
12/04/2015 - ACA: Underline in Tag But Not in Schedule III
04/11/2017 - ACA: Property Set Definitions, Applies To - Just How Many Polyline Types Are There?
05/23/2017 - ACA: Wall Rotation Property
01/14/2019 - ACA: Accessing AEC Data in Formula Properties for Multiple Versions
09/11/2019 - ACA: Rotation Property for Multi-View Blocks