COD SCRIPTING AND NULL VALUES

Recently a collogue and I were brainstorming a simple CAM script to remove Stiffeners for all Items with a Dimension named “Length”, who’s value is under 30″… (This is obviously not an all-encompassing solution. What if the Fabrication Part in question is 100″ wide? We may want Stiffeners here!)

However, in many cases we spend a lot of scripting time and effort string searching for specific Dimension or Option Names, checking Connector.Count, or Item.CID etc. All so we can isolate the specific Items we want to work with and no more. In many cases we can leverage Null values here. Please consider the following example.

Dim LengthDim = Item.Dim["Length"]
REM Check if a length dimension object even exists first…
If LengthDim Then
    If LengthDim.Value < 30 Then
        Dim Stiffener = Item.Stiffener[1]
        REM Check if a stiffener object even exists at this index first…
        If Stiffener Then
            Stiffener.Locked=False
            Stiffener.Value="None"
            Stiffener.Locked=True
            Item.Update()
            End If
        End If
End IF

Unless our COD code is extremely specific about which Disk Items we want to work with, we can’t EVER assume that a specific Item’s Connector Index, Dimension/Option Value, Lock, Air Turn, Seam etc. even exists! We also cannot assume that certain Item Properties are even relevant in the context of the problem that we are trying to solve. CID 7 for example could be a Shoe Tap, a Straight Tap, or even a Straight with a Damper. Filtering on CID and Dimension Name alone doesn’t always work so be careful!

I am by no means a COD scripting expert but this is a technique that is used in almost any language, and is something I have found extremely valuable when dealing with these issues.

http://www.xtracad.com/forum/index.php/topic,16667.0.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s