こちらでもアナウンスされているAPIでのJavascript非対応
Notice: Javascript API is being fully retired - Autodesk Community
今回のUpdateかな?と思っていたのですが・・・。
予想を裏切り、ここ残っています。
コマンド一覧を表示させる
neuDev.listFunctions()
生きているみたい。まだ機能しているのかな?
上記と無関係なのですが、スケッチテキストの水平と垂直の向きを反転
させるだけのサンプルを作ったのですが、Helpをよく見たらプロパティが
有ったので、全く無駄なコードです。
これ自体は無意味(プロパティで行うべきです)なのですが、
個人的には収穫ありました。記念に掲載。
#Fusion360API Python script import adsk.core, adsk.fusion, traceback _app = adsk.core.Application.cast(None) _ui = adsk.core.UserInterface.cast(None) def run(context): try: global _app, _ui _app = adsk.core.Application.get() _ui = _app.userInterface _app.documents.add(adsk.core.DocumentTypes.FusionDesignDocumentType) des :adsk.fusion.Design = _app.activeProduct root :adsk.fusion.Component = des.rootComponent # Extended Methods adsk.core.Selections.forcedClear = forcedClear # create sketch skt :adsk.fusion.Sketch = root.sketches.add(root.xYConstructionPlane) # create sketchText pnt3D = adsk.core.Point3D sktTxts :adsk.fusion.sketchTexts = skt.sketchTexts sktTxtIpt :adsk.fusion.SketchTextInput= sktTxts.createInput( 'example', 5.0, pnt3D.create(1.0, 1.0, 1.0)) sktTxt :adsk.fusion.SketchText = sktTxts.add(sktTxtIpt) # get selections sels :adsk.core.Selections = _ui.activeSelections # start EditSketch sels.forcedClear() sels.add(skt) _app.executeTextCommand(u'Commands.Start SketchActivate') # Start EditText command sels.forcedClear() sels.add(sktTxt) _app.executeTextCommand(u'Commands.Start EditTextCmd') # message _ui.messageBox('TextFlip changes') # HorizontalFlip _app.executeTextCommand(u'Commands.ChildItemSelect TextFlip HorizontalFlip 1') # VerticaltalFlip _app.executeTextCommand(u'Commands.ChildItemSelect TextFlip VerticaltalFlip 1') # End EditText command _app.executeTextCommand(u'Commands.Start EditTextCmd') _app.executeTextCommand(u'Commands.Start CommitCommand') except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def forcedClear(self :adsk.core.Selections): app = adsk.core.Application.get() self.clear() if self.count > 0: ents = self.all app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd') [self.add(ent) for ent in ents] app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd') self.clear()
追加です。
テキストの角度を変更するためのスクリプトも作ったけど無駄だった。
最初プロパティの変更ではエラーだったから作ったのに、プロパティの変更でOKだった。
#Fusion360API Python script import adsk.core, adsk.fusion, traceback import math _app = adsk.core.Application.cast(None) _ui = adsk.core.UserInterface.cast(None) def run(context): sketchTextAngle :float = 50 # unit Degree try: global _app, _ui _app = adsk.core.Application.get() _ui = _app.userInterface # Select SketchText msg :str = 'Select Sketch Text' selFiltter :str = 'Texts' sel :adsk.core.Selection = selectEnt(msg ,selFiltter) if not sel: return # get SketchText sktTxt :adsk.fusion.SketchText = sel.entity beforeAng = math.degrees(sktTxt.angle) # change SketchText Angle changeSketchTextAngle(sktTxt, sketchTextAngle) # finish afterAng = math.degrees(sktTxt.angle) _ui.messageBox('Done\n{:.2f}deg -> {:.2f}deg'.format(beforeAng , afterAng)) except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def changeSketchTextAngle( sktTxt :adsk.fusion.SketchText, angle :float # Degree ): app = adsk.core.Application.get() ui = app.userInterface # Extended Methods adsk.core.Selections.forcedClear = forcedClear try: # get parentSketch skt :adsk.fusion.sketch = sktTxt.parentSketch # check Sketch des :adsk.fusion.Design = app.activeProduct stateObj = des.activeEditObject exitSktFg = True if stateObj.objectType == 'adsk::fusion::Sketch': if stateObj == skt: exitSktFg = False # deg to rad rad :float = math.radians(angle) # get selections sels :adsk.core.Selections = _ui.activeSelections # start EditSketch sels.forcedClear() sels.add(skt) _app.executeTextCommand(u'Commands.Start SketchActivate') # Start EditText command sels.forcedClear() sels.add(sktTxt) _app.executeTextCommand(u'Commands.Start EditTextCmd') # change angle _app.executeTextCommand(u'Commands.SetDouble TextAngle {}'.format(rad)) # End EditText command _app.executeTextCommand(u'Commands.Start EditTextCmd') _app.executeTextCommand(u'Commands.Start CommitCommand') # End start EditSketch if exitSktFg: _app.executeTextCommand(u'Commands.Start SketchStop') except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) finally: adsk.core.Selections.forcedClear = None def forcedClear(self :adsk.core.Selections): app = adsk.core.Application.get() self.clear() if self.count > 0: ents = self.all app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd') [self.add(ent) for ent in ents] app.executeTextCommand(u'Commands.Start SelectabilityToggleCmd') self.clear() def selectEnt( msg :str, filtterStr :str ) -> adsk.core.Selection : try: sel = _ui.selectEntity(msg, filtterStr) return sel except: return None