Option Explicit
Implements ApplicationAddInServer
Private oApp As Inventor.Application
Private WithEvents oButtonHandler1 As ButtonDefinitionHandler
Private WithEvents oButtonHandler2 As ButtonDefinitionHandler
Private Sub ApplicationAddInServer_Activate(ByVal AddInSiteObject As
Inventor.ApplicationAddInSite _
, ByVal FirstTime As Boolean)
' Save a reference to the Application object.
Set oApp = AddInSiteObject.Application
' Create the two button handlers. To simplify this sample the icons
' are read from disk. They could also have been obtained from other
' various sources such as an image list control or a resource file.
' Also, to simplify this sample only small buttons are used. Inventor
' will scale them if large buttons are selected by the user.
Dim oIcon1 As IPictureDisp
Dim oIcon2 As IPictureDisp
Set oIcon1 = LoadPicture(App.Path & "\Slot.ico")
Set oIcon2 = LoadPicture(App.Path & "\Toggle.ico")
Set oButtonHandler1 =
AddInSiteObject.CreateButtonDefinitionHandler("AddInSampleCmd1", _
kShapeEditCmdType, "Draw Slot", "Create slot
sketch graphics", _
"Draw Slot", oIcon1, oIcon1)
Set oButtonHandler2 =
AddInSiteObject.CreateButtonDefinitionHandler("AddInSampleCmd2", _
kQueryOnlyCmdType, "Toggle Slot State",
"Enables/Disables state of slot command.", _
"Toggle Slot State", oIcon2, oIcon2)
' Create a new command bar
Dim oCommandBar As CommandBarBase
Set oCommandBar =
oApp.EnvironmentBaseCollection.CommandBarBaseCollection.Add("AddIn Sample")
' Add buttons to the command bar for the two handlers.
Call oCommandBar.Controls.Add(kBarControlButton,
oButtonHandler1.ControlDefinition)
Call oCommandBar.Controls.Add(kBarControlButton,
oButtonHandler2.ControlDefinition)
' Get the 2d sketch environment base object.
Dim oEnvBase As EnvironmentBase
Set oEnvBase =
oApp.EnvironmentBaseCollection.Item("PMxPartSketchEnvironment")
' Make this command bar accessable in the panel menu for the 2d sketch
environment.
oEnvBase.PanelBarList.Add oCommandBar
MsgBox "To access the commands of the sample add-in, activate a 2d
sketch in a part" & Chr(13) & _
"document and select the ""AddIn Sample"" toolbar within the
panel menu."
End Sub
Private Property Get ApplicationAddInServer_Automation() As Object
Set ApplicationAddInServer_Automation = Nothing
End Property
Private Sub ApplicationAddInServer_Deactivate()
' Release all references.
Set oButtonHandler1 = Nothing
Set oButtonHandler2 = Nothing
Set oApp = Nothing
End Sub
Private Sub ApplicationAddInServer_ExecuteCommand(ByVal CommandID As Long)
' No longer used.
End Sub
Private Sub oButtonHandler1_OnClick()
' Check to make sure a sketch is active.
If TypeOf oApp.ActiveEditObject Is PlanarSketch Then
' Call the method to draw the sketch.
Call DrawSlot(oApp.ActiveEditObject)
Else
' No sketch is active so display an error.
MsgBox "A sketch must be active for this command."
End If
End Sub
Private Sub oButtonHandler2_OnClick()
' Toggle the enabled state of command 1.
If oButtonHandler1.Enabled Then
oButtonHandler1.Enabled = False
Else
oButtonHandler1.Enabled = True
End If
End Sub
Private Sub DrawSlot(oSketch As PlanarSketch)
Dim oLines(1 To 2) As SketchLine
Dim oArcs(1 To 2) As SketchArc
Dim oTransGeom As TransientGeometry
' Start a transaction so the slot will be within a single undo step.
Dim oTrans As Transaction
Set oTrans =
oApp.TransactionManager.StartTransaction(oApp.ActiveDocument, "Create Slot")
' Draw the lines and arcs that make up the shape of the slot.
With oApp.TransientGeometry
Set oLines(1) = oSketch.SketchLines.AddByTwoPoints( _
.CreatePoint2d(0, 0), .CreatePoint2d(5, 0))
Set oArcs(1) = oSketch.SketchArcs.AddByCenterStartEndPoint( _
.CreatePoint2d(5, 1), oLines(1).EndSketchPoint, _
.CreatePoint2d(5, 2))
Set oLines(2) = oSketch.SketchLines.AddByTwoPoints( _
oArcs(1).EndSketchPoint, .CreatePoint2d(0, 2))
Set oArcs(2) = oSketch.SketchArcs.AddByCenterStartEndPoint( _
.CreatePoint2d(0, 1), oLines(2).EndSketchPoint, _
oLines(1).StartSketchPoint)
End With
' Create the tangent constraints between the lines and arcs.
Call oSketch.GeometricConstraints.AddTangent(oLines(1), oArcs(1))
Call oSketch.GeometricConstraints.AddTangent(oLines(2), oArcs(1))
Call oSketch.GeometricConstraints.AddTangent(oLines(2), oArcs(2))
Call oSketch.GeometricConstraints.AddTangent(oLines(1), oArcs(2))
' Create a parallel constraint between the two lines.
Call oSketch.GeometricConstraints.AddParallel(oLines(1), oLines(2))
' End the transaction.
oTrans.End
End Sub
"Neil Munro" wrote in message news:41827907_3@newsprd01...
> What IV version? The help file Add-In sample program does not create any
> buttons or toolbars. Did you add code to do this? Could you post the code
> from the .cls file?
>
> Neil
>
> "Calimesa" wrote in message
> news:4182746c_1@newsprd01...
> > yes, I saw it in the Tool>Add-ins and loaded.
> >
> > "Neil Munro" wrote in message
> > news:418273cb$1_3@newsprd01...
> >> Select Tools > Add-ins from the menu. Does the add-in appear in the
list?
> > If
> >> so, does it show as loaded?
> >>
> >> Neil
> >>
> >> "Calimesa" wrote in message
> >> news:41827287_2@newsprd01...
> >> >I followed exactly step-by-step showing in the program help. After
> > compile
> >> > the DLL register the registry, run IV, I couldn't see the AddIn
Sample
> >> > Toolbar in the Panel bar
> >> > Anyone experieced this before, Please give out a hint.
> >> > Thanks.
> >> >
> >> >
> >>
> >>
> >
> >
> >
>
>