Вы находитесь на странице: 1из 9

8.10.

2014

Autodesk Inventor API. /

Autodesk Inventor API. /


< Autodesk Inventor API.


, ,
, .

1
2 VBA
3
4
5
6 Flush_XYZ


,
XY, YZ XZ .
,
.
Flush_XYZ, .
Flush_XYZ ,
.

VBA
VBA.
VBA ALt-F11. Project
. Module1.
. , .
.

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

1/9

8.10.2014

Autodesk Inventor API. /

Option Explicit.
. .
VBA , 'Options' ,
.

Copy/Paste Flush_XYZ.

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

2/9

8.10.2014

Autodesk Inventor API. /

Ctrl-S.


, Part1, Part2, .
, .
(Grounded) .
, Flush_XYZ .


, Flush_XYZ.
VBA 'Macros, Alt-F8.
:

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

3/9

8.10.2014

Autodesk Inventor API. /

: Macro name , Macros in:.


, , . Run, ,

:

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

4/9

8.10.2014

Autodesk Inventor API. /

, .
, ,
.


, .
. ' .
, , .. , ,
- .
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
Flush_XYZ
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'
'
' XY, YZ XZ
'
' .
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

(Sub) Flush_XYZ ,
. . VBA
(Public Sub) ( ).
Public Sub Flush_XYZ()

End Sub
' Flush_XYZ

, Dim( . dimension ),
.
Dim oApp
As Inventor.Application
' Inventor
Dim oAsmCompDef As AssemblyComponentDefinition '
Dim oCompOcc
As ComponentOccurrence
'
Dim oSelectSet As SelectSet

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

5/9

8.10.2014

Autodesk Inventor API. /

oApp () Inventor, Application.


oApp .
oAsmCompDef .
oCompOcc ,
, .
oSelectSet SelectSet , ..
.
,
.
Dim oAsmPlane
As WorkPlane
'
Dim oPartPlane
As WorkPlane
'
Dim oPartPlaneProxy As WorkPlaneProxy 'proxy-

i:
Dim i As Long ' 1,2,3

.
INVENTOR oApp:
Set oApp = ThisApplication

,
? , .
': ?
If oApp.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MsgBox " ."
Exit Sub
End If

, ,
oAsmCompDef, .
Set oAsmCompDef = oApp.ActiveDocument.ComponentDefinition

, ( ) .
SelectSet .
oSelectSet:
' SelectSet
Set oSelectSet = oApp.ActiveDocument.SelectSet

. , ,
, - (, ).
, .
':
If oSelectSet.Count <> 1 Then
MsgBox " ."
Exit Sub
End If
':

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

6/9

8.10.2014

Autodesk Inventor API. /

If Not (TypeOf oSelectSet.Item(1) Is ComponentOccurrence) Then


MsgBox " ."
Exit Sub
End If

.
' ()
Set oCompOcc = oSelectSet.Item(1)

.
"_XYZ". ,
StartTransaction End Undo.
'
Dim oConstrTransaction As Transaction
Set oConstrTransaction = oApp.TransactionManager. _
StartTransaction(oApp.ActiveDocument, "_XYZ")

oConstrTransaction.End '

, , ,
oCompOcc
XY, YZ XZ .
' .
' i=1:
' i=2:
' i=3:

YZ,
ZX,
XY,

- X
- Y
- Z

For i = 1 To 3
' i
Set oAsmPlane = oAsmCompDef.WorkPlanes.Item(i)
' i
Set oPartPlane = oCompOcc.Definition.WorkPlanes.Item(i)
' -
Call oCompOcc.CreateGeometryProxy(oPartPlane, oPartPlaneProxy)
' ""
' -
Call oAsmCompDef.Constraints.AddFlushConstraint( _
oAsmPlane, oPartPlaneProxy, 0)
Next i

,
FlushConstraint (). oAsmCompDef Constraints
. AddFlushConstraint(oAsmPlane, oPartPlaneProxy, 0)
oAsmPlane oPartPlaneProxy
. .
,
, -, ..
- .

Flush_XYZ

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

7/9

8.10.2014

Autodesk Inventor API. /

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
Flush_XYZ
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'
'
'
' XY, YZ XZ
'
' .
': , 2007
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Public Sub Flush_XYZ()
Dim oApp
As Inventor.Application
' Inventor
Dim oAsmCompDef As AssemblyComponentDefinition '
Dim oCompOcc
As ComponentOccurrence
'
Dim oSelectSet As SelectSet
Dim oAsmPlane
As WorkPlane
'
Dim oPartPlane
As WorkPlane
'
Dim oPartPlaneProxy As WorkPlaneProxy 'proxy-
Dim i As Long ' 1,2,3
' INVENTOR
Set oApp = ThisApplication
': ?
If oApp.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MsgBox " ."
Exit Sub
End If
'
Set oAsmCompDef = oApp.ActiveDocument.ComponentDefinition
' SelectSet
Set oSelectSet = oApp.ActiveDocument.SelectSet
':
If oSelectSet.Count <> 1 Then
MsgBox " ."
Exit Sub
End If
':
If Not (TypeOf oSelectSet.Item(1) Is ComponentOccurrence) Then
MsgBox " ."
Exit Sub
End If
' ()
Set oCompOcc = oSelectSet.Item(1)
'
Dim oConstrTransaction As Transaction
Set oConstrTransaction = oApp.TransactionManager. _
StartTransaction(oApp.ActiveDocument, "_XYZ")

' .
' i=1:
' i=2:
' i=3:

YZ,
ZX,
XY,

- X
- Y
- Z

For i = 1 To 3
' i
Set oAsmPlane = oAsmCompDef.WorkPlanes.Item(i)
' i
Set oPartPlane = oCompOcc.Definition.WorkPlanes.Item(i)
' -
Call oCompOcc.CreateGeometryProxy(oPartPlane, oPartPlaneProxy)
' ""
' -
Call oAsmCompDef.Constraints.AddFlushConstraint(oAsmPlane, oPartPlaneProxy, 0)
Next i
oConstrTransaction.End '

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

8/9

8.10.2014
End Sub

Autodesk Inventor API. /


' Flush_XYZ

http://ru.wikibooks.org/w/index.php?title=Autodesk_Inventor_API.__/_&oldid=45871
: Autodesk Inventor API.
: 18:33, 19 2009.
Creative Commons Attribution-ShareAlike,
. . .

http://ru.wikibooks.org/wiki/Autodesk_Inventor_API._%D0%9F%D0%B5%D1%80%D0%B2%D1%8B%D0%B5_%D1%88%D0%B0%D0%B3%D0%B8/%D

9/9

Оценить