API 範例:建立多個落差

您可以透過「應用程式介面」(API) 建立新的圖元。此範例會為在所選節點澆注的熱流道系統建立圖元,然後為新圖元建立網格。您可以在產品安裝目錄之 data/dat 目錄內的 tcodes.dattcodeset.dat 檔案中,找到性質中使用的數值 (在此範例中為五位數的常數)。

註: tcodeset 參考可協助您瞭解如何在指令碼中使用性質。
'@
'@ DESCRIPTION
'@ This command will run all Models in the current directory   
'@ 
'@
'@ SYNTAX
'@ CreateDrops
'@
'@ PARAMETERS
'@ none 
'@
'@ DEPENDENCIES/LIMITATIONS
'@
'@ History
'@ Created DRA 9/8/2006
'@@ 
Option Explicit
SetLocale("en-us")
Dim Synergy
Set Synergy = CreateObject("synergy.Synergy")
Synergy.SetUnits "METRIC"

Dim  StudyDoc, PropEd, Modeler, MeshGenerator, Viewer
Dim SelectList, Prop, DVec, DVec1, HotGateCount, HotRunCount
Dim I, nodeCoord, BaseX, BaseY, BaseZ, Vector, Vector_1, EntList

Set StudyDoc = Synergy.StudyDoc()
If StudyDoc is Nothing Then
        MsgBox "No Active Study",,"Error"
        WScript.Quit
End If

Set SelectList = StudyDoc.Selection
If SelectList.Size = 0 Then
        MsgBox "No Entities have been selected",,"Error"
        WScript.Quit
End If

Set PropEd = Synergy.PropertyEditor()
Set Modeler = Synergy.Modeler()
  
' Create Properties for Gate
<em class="strong">HotGateCount = GetLastTsetID(40434) + 1
Set Prop = PropEd.CreateProperty(40434, HotGateCount, True)
Set DVec = Synergy.CreateDoubleArray()
DVec.AddDouble 2
Prop.FieldValues 30212, DVec
Set DVec1 = Synergy.CreateDoubleArray()
DVec1.AddDouble 1.5
DVec1.AddDouble 5
Prop.FieldValues 30262, DVec1
PropEd.CommitChanges ""</em>

' Create Properties for Drop
<em class="strong">HotRunCount = GetLastTsetID(40430) + 1
Set Prop = PropEd.CreateProperty(40430, HotRunCount, True)
Set DVec = Synergy.CreateDoubleArray()
DVec.AddDouble 10
Prop.FieldValues 30260, DVec
PropEd.CommitChanges ""</em>

' Loop Through Slected Nodes and create Gates and Drops
For I = 0 To SelectList.Size()-1
        Dim Ent
        Set Ent = SelectList.Entity(I)
        Dim EntName
        EntName = Ent.ConvertToString
        <em class="strong">If ( Left(EntName, 1) = "N") Then 
                Set  nodeCoord = StudyDoc.GetNodeCoord(Ent)
                BaseX = nodeCoord.X
                BaseY = nodeCoord.Y
                BaseZ = nodeCoord.Z
                Set Vector = Synergy.CreateVector()
                Set Vector_1 = Synergy.CreateVector()
                Set Modeler = Synergy.Modeler()
                ' Create Gate
                Set Prop = Modeler.FindProperty(40434, HotGateCount)
                Vector.SetXYZ BaseX, BaseY, BaseZ
                Vector_1.SetXYZ 0, 0, 5
                Set EntList = Modeler.CreateLine(Vector, Vector_1, True, Prop, True)
                PropEd.SetProperty EntList, Prop
                ' Create Drop   
                Set Prop = Modeler.FindProperty(40430, HotRunCount)
                Vector.SetXYZ BaseX, BaseY, BaseZ+5
                Vector_1.SetXYZ 0, 0, 100
                Set EntList = Modeler.CreateLine(Vector, Vector_1, True, Prop, True)
                PropEd.SetProperty EntList, Prop
        End If</em>
Next

' Save All Proerty Data
PropEd.CommitChanges "Assign"

' Mesh the new drops
<em class="strong">Set MeshGenerator = Synergy.MeshGenerator()
MeshGenerator.Generate</em>

' Display Updated Model
<em class="strong">Set Viewer = Synergy.Viewer()
Viewer.Fit</em>

' Exist Script
MsgBox "Script Complete"
WScript.Quit

' Function to Find Last Instance of a Tset in the Study File
Private Function GetLastTsetID(Tset)

        GetLastTsetID = 0
        Dim Project, PropEd
        Set Project = Synergy.Project()
        Set PropEd = Synergy.PropertyEditor()
        Dim TestPropertyID
        Set TestPropertyID = PropEd.GetFirstProperty(Tset)
        While Not TestPropertyID Is Nothing
                GetLastTsetID = TestPropertyID.ID
                if TestPropertyID.ID &gt; GetLastTsetID Then
                        GetLastTsetID = TestPropertyID.ID
                End if
                Set TestPropertyID = PropEd.GetNextPropertyOfType(TestPropertyID)
        Wend
        
End Function