



Random Thoughts |
Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. - Albert Einstein
|

言語 |
|




|
 |
フォーラムニュース: 質問、相談カテゴリに「SolidWorks操作方法」に関するフォーラムを追加しました。(2003/11/27) |
いらっしゃい、 ゲストさん. まずはこちら→ ログイン または 登録. 2025/02/19 - 06:54:56 |
|
 |
|

著者
|
トピック: アセンブリ構成部品の回転 (閲覧数 4099 回) |
|
jimnii
新人さん 
オフライン
投稿: 1

I'm a llama!
|
 |
アセンブリ構成部品の回転
« 投稿日: 2011/08/29 - 12:34:49 » |
|
初投稿させていただきます。
現在,InputBoxなどを用いて画面上に角度入力BOXを表示させ,入力した角度でアセンブリ構成部品をZ軸を基準に回転するようなものを作成しているのですがうまくいきません。。。
まだ,始めたばかりのため理解できてないことも多くあるのですが,よろしくお願いいたします。
|
|
|
|
Makoron
カタマリの王様!?     
オフライン
投稿: 1277

SW2011SP5.0
|
 |
Re:アセンブリ構成部品の回転
« 返信 #1 投稿日: 2011/10/25 - 11:57:13 » |
|
jimniiさん、はじめまして。
かなり時間がたっているので解決されているかもしれませんが、 サンプルを作ってみました。 ちなみに、サンプルはAPIマニュアルの「Rotate Assembly Component on Axis Example (VB) 」を参考にしています。
Code:Option Explicit
Const RAD_PAR_DEG As Double = 3.14159 / 180#
Sub main() Dim swApp As SldWorks.SldWorks Dim swModelDoc2 As SldWorks.ModelDoc2 Dim swAssemblyDoc As SldWorks.AssemblyDoc Set swApp = Application.SldWorks Set swModelDoc2 = swApp.ActiveDoc Set swAssemblyDoc = swModelDoc2 ' 選択されている構成部品を取得 Dim swSelectionMgr As SldWorks.SelectionMgr Dim vntSelObject As Variant Dim swComponent2 As SldWorks.Component2 Set swSelectionMgr = swModelDoc2.SelectionManager If swSelectionMgr.GetSelectedObjectCount2(-1) <> 1 Then MsgBox ("対象となる構成部品をフィーチャツリーから選択してマクロを実行してください。" & vbCrLf & "マクロを終了します。") End End If If swSelectionMgr.GetSelectedObjectType3(1, -1) <> swSelectType_e.swSelCOMPONENTS Then MsgBox ("対象となる構成部品をフィーチャツリーから選択してマクロを実行してください。" & vbCrLf & "マクロを終了します。") End End If Set vntSelObject = swSelectionMgr.GetSelectedObject6(1, -1) Set swComponent2 = vntSelObject
' 回転角度のユーザー入力 Dim strImput As String Dim dblAngle As Double strImput = InputBox("構成部品のZ軸回転方向を入力", "角度の入力") dblAngle = CDbl(strImput)
' 構成部品の回転パラメータを作成 Dim swMathUtil As SldWorks.MathUtility Dim dblPts(2) As Double Dim vntData As Variant Dim swOriginPt As SldWorks.MathPoint Dim swZAxis As SldWorks.MathVector Dim swXform As SldWorks.MathTransform Set swMathUtil = swApp.GetMathUtility dblPts(0) = 0# dblPts(1) = 0# dblPts(2) = 0# vntData = dblPts Set swOriginPt = swMathUtil.CreatePoint(vntData) dblPts(0) = 0# dblPts(1) = 0# dblPts(2) = 1# vntData = dblPts Set swZAxis = swMathUtil.CreateVector(vntData) Set swXform = swMathUtil.CreateTransformRotateAxis(swOriginPt, swZAxis, dblAngle * RAD_PAR_DEG)
' 構成部品を回転 Dim swDragOp As SldWorks.DragOperator Set swDragOp = swAssemblyDoc.GetDragOperator Call swDragOp.AddComponent(swComponent2, False) swDragOp.CollisionDetectionEnabled = False swDragOp.DynamicClearanceEnabled = False swDragOp.TransformType = 1 swDragOp.DragMode = 2 Call swDragOp.BeginDrag Call swDragOp.Drag(swXform) Call swDragOp.EndDrag End Sub
|
|
|
|
|
|
|
|

|