最近在更新過的 Inventor 2019 版上執行以功能會發生以下錯誤:
"UnitTypeEnum未宣告。可能因為它的保護層級而導致無法存取。"
本來以為是我的電腦設定造成,例如資料夾保護設定、病毒程式防護等等,
後來關掉一堆系統保護都沒用,
回過頭看 iLogic 提供的參數指令,
在 2019 版多提供有關公差跟讀取外部 xml 檔建立新參數的功能,
有可能是因為如此而在 Inventor 程式中拿掉有關 UnitTypeEnum 宣告所造成,
所以新的方法是使用"載入 XML":
2019 iLogic 載入參數(包括建立新參數) |
再使用文字編輯器去看,應該不難理解裡面的參數定義,
所以可以自行刪除、新增、編輯 xml 內容來控制執行 "載入 XML"要載入(含新建)參數。
以下適用 Inventor 2019R.2 之前版本。
在使用 Inventor 的過程中,
範本檔經常會"與時俱進"的進行"進化",
常見的就是配合需求增加使用者自定參數,
但是如果是早期建立的範本檔通常就會缺少這些後期所建立的使用者自訂參數,
可能造成某些"規則"或"表單"找不到參數而無法執行,
所以如果可以在一些使用到這些新參數的規則中加入一個偵測參數存在與否,
並且可以在找不到參數的情況下自動建立新參數就太好了。
再次請出 Google 大神,下搜尋關鍵字:
" inventor ilogic create parameter not exist "
果然在第一條就找到!
國外的高手實在是又多又讚!
狀況如下:
如果我們要使用三個在原本檔案中不存在的參數:
名稱(文字)、鍍膜厚度(數值)、輸出與否(真/假)三種不同型式的使用者自訂參數,
可以使用以下語法:
oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters
第一行是宣告啟用使用者自訂參數設訂物件: oMyParameter
PS.
有時候會跟 Inventor 某些功能相衝,會找不到成員而發生錯誤,
將 Inventor 關掉再重新開啟就可以,這應該算是 Inventor 系統的 Bug.
Try
Parameter("名稱") = Parameter("名稱")
測試參數"名稱"是否存在
Catch
oParameter=oMyParameter.AddByValue("名稱","基板",UnitTypeEnum.kTextUnits)
如果參數"名稱"不存在就建立一個文字型式(UniTypeEnum.kTextUnits)的使用者參數"名稱",並且指定其值為"基板"
End Try
結束 Try
完整的建立三種使用者參數的範例如下:
oMyParameter = ThisApplication.ActiveDocument.ComponentDefinition.Parameters.UserParameters Try Parameter("名稱") = Parameter("名稱") Catch oParameter=oMyParameter.AddByValue("名稱","基板",UnitTypeEnum.kTextUnits) End Try Try Parameter("鍍膜厚度") = Parameter("鍍膜厚度") Catch oParameter=oMyParameter.AddByValue("鍍膜厚度",20,UnitTypeEnum.kMicronLengthUnits) End Try Try Parameter("輸出與否") = Parameter("輸出與否") Catch oParameter=oMyParameter.AddByValue("輸出與否",True,UnitTypeEnum.kBooleanUnits) End Try
其中 UnitTypeEnum 後面指定的參數型式(數值、文字或真假)跟單位可以參考如下表:
Name | Value | Description |
kAcreAreaUnits | 11301 | Acre Area. |
kAmpElectricalCurrentUnits | 11327 | Amp electrical Current. |
kBooleanUnits | 11347 | Boolean (Yes/No). |
kBTUWorkUnits | 11320 | BTU Work. |
kCalorieWorkUnits | 11319 | Calorie Work. |
kCandelaLuminousIntensityUnits | 11342 | Candela luminous intensity. |
kCelsiusTemperatureUnits | 11296 | Celsius Temperature. |
kCentimeterLengthUnits | 11268 | Centimeter Length. |
kCircularMilAreaUnits | 11326 | CircularMil Area. |
kCompositeUnits | 11322 | Composite. |
kCoulombElectricalChargeUnits | 11330 | Coulomb electrical Charge. |
kCupVolumeUnits | 11306 | Cup Volume. |
kDatabaseAngleUnits | 11277 | Database units for angle -- ALWAYS Radian. |
kDatabaseLengthUnits | 11267 | Database units for length -- ALWAYS Centimeter. |
kDatabaseMassUnits | 11282 | Database units for mass -- ALWAYS Kilogram. |
kDatabaseTemperatureUnits | 11294 | Database units for temperature -- ALWAYS Kelvin. |
kDatabaseTimeUnits | 11289 | Database units for time -- ALWAYS Second. |
kDefaultDisplayAngleUnits | 11276 | Current default display units for Angle. |
kDefaultDisplayLengthUnits | 11266 | Current default display units for length. |
kDefaultDisplayMassUnits | 11281 | Current default display units for Mass. |
kDefaultDisplayTemperatureUnits | 11293 | Current default display units for Temperature. |
kDefaultDisplayTimeUnits | 11288 | Current default display units for Time. |
kDegreeAngleUnits | 11279 | Degree Angle. |
kDyneForceUnits | 11312 | Dyne Force. |
kErgWorkUnits | 11318 | Erg Work. |
kFahrenheitTemperatureUnits | 11297 | Fahrenheit Temperature. |
kFaradElectricalCapacitanceUnits | 11331 | Farad electrical Capacitance. |
kFeetPerSecondSpeedUnits | 11299 | FeetPerSecond Speed. |
kFootLengthUnits | 11273 | Foot Length. |
kGallonVolumeUnits | 11303 | Gallon Volume. |
kGammaMagneticInductionUnits | 11337 | Gamma magnetic Induction. |
kGaussMagneticInductionUnits | 11338 | Gauss magnetic Induction. |
kGradAngleUnits | 11280 | Grad Angle. |
kGramMassUnits | 11284 | Gram Mass. |
kHenryElectricalInductanceUnits | 11339 | Henry electrical Inductance. |
kHertzFrequencyUnits | 11341 | Hertz Frequency. |
kHorsePowerPowerUnits | 11316 | HorsePower Power. |
kHourTimeUnits | 11292 | Hour Time. |
kInchLengthUnits | 11272 | Inch Length. |
kJouleWorkUnits | 11317 | Joule Work. |
kKelvinTemperatureUnits | 11295 | Kelvin Temperature. |
kKilogramMassUnits | 11283 | Kilogram Mass. |
kKSIPressureUnits | 11310 | KSI Pressure. |
kLbForceUnits | 11313 | Lb Force. |
kLbMassMassUnits | 11286 | LbMass Mass. |
kLiterVolumeUnits | 11302 | Liter Volume. |
kLumenLuminousFluxUnits | 11343 | Lumen luminous flux. |
kLuxIlluminationUnits | 11344 | Lux illumination. |
kMaxwellMagneticFluxUnits | 11335 | Maxwell magnetic Flux. |
kMeterLengthUnits | 11270 | Meter Length. |
kMetersPerSecondSpeedUnits | 11298 | MetersPerSecond Speed. |
kmhoElectricalConductanceUnits | 11333 | mho electrical Conductance. |
kMicronLengthUnits | 11271 | Micron Length. |
kMileLengthUnits | 11275 | Mile Length. |
kMilesPerHourSpeedUnits | 11300 | MilesPerHour Speed. |
kMilLengthUnits | 11324 | Mil Length. |
kMillimeterLengthUnits | 11269 | Millimeter Length. |
kMinuteTimeUnits | 11291 | Minute Time. |
kMoleSubstanceUnits | 11345 | Mole Substance or gram molecular weight. |
kNauticalMileLengthUnits | 11323 | NauticalMile Length. |
kNewtonForceUnits | 11311 | Newton Force. |
kOerstedMagneticInductionUnits | 11340 | Oersted magnetic Induction. |
kOhmElectricalResistanceUnits | 11329 | Ohm electrical Resistance. |
kOunceForceUnits | 11314 | Ounce Force. |
kOunceMassUnits | 11287 | Ounce Mass. |
kOunceVolumeUnits | 11307 | Ounce Volume. |
kPascalPressureUnits | 11308 | Pascal Pressure. |
kPintVolumeUnits | 11305 | Pint Volume. |
kPSIPressureUnits | 11309 | PSI Pressure. |
kQuartVolumeUnits | 11304 | Quart Volume. |
kRadianAngleUnits | 11278 | Radian Angle. |
kRPMAngularVelocityUnits | 11321 | RPM AngularVelocity. |
kSecondTimeUnits | 11290 | Second Time. |
kSiemensElectricalConductanceUnits | 11332 | Siemens electrical Conductance. |
kSlugMassUnits | 11285 | Slug Mass. |
kSteradianAngleUnits | 11325 | Steradian Angle. |
kTeslaMagneticInductionUnits | 11336 | Tesla magnetic Induction. |
kTextUnits | 11346 | Text (String). |
kUnitlessUnits | 11265 | No dimension associated with this value. |
kVoltElectricalVoltageUnits | 11328 | Volt electrical Voltage. |
kWattPowerUnits | 11315 | Watt Power. |
kWeberMagneticFluxUnits | 11334 | Weber magnetic Flux. |
kYardLengthUnits | 11274 | Yard Length. |