马上注册,结交更多同行朋友,交流,分享,学习。
您需要 登录 才可以下载或查看,没有帐号?注册
x
我的代码要实现的功能事要实现把一个文件存到SmarTeam的库里面去,麻烦高手帮我调一下。我是用VB做的
'function create engine, session, open database connect
Public Sub cmdLogin()
Dim SmDatabase As SmDatabase
Dim SmGuiStore As ISmGUIStore
On Error GoTo ErrExit
Screen.MousePointer = vbHourglass
'create new engine
Set Engine = New SmApplic.SmEngine
'init engine
Engine.Init "SmTeam32"
'create session object
Set Session = Engine.CreateSession("Api_Training", "SmTeam32.ini")
'Set Session = New SmApplic.SmSession
Set SmDatabase = Engine.Databases(0)
'connect to database
Session.OpenDatabaseConnection SmDatabase.Alias, SmDatabase.Password, True
'Session.OpenDatabaseConnection "SmartDB", "szuwir", True
Set GUIService = Session.GetService("SmGUISrv.SmGUIServices")
Set SmGuiStore = GUIService.GUIStore
If (GUIService.GUIStore.LogIn = False) Then
MsgBox "connect failed"
Exit Sub
End If
'user login with session
'Session.UserLogin "joe", ""
Screen.MousePointer = vbNormal
'MsgBox "Connection Successful!"
Set SmCommonGUI = Session.GetService("SmGUISrv.SmCommonGUI")
'SmGuiStore.OpenQueryByAttribute (swsNormal)
Exit Sub
ErrExit:
MsgBox Err.Description
End Sub
Public Sub Add_File3() 'Save as file
Dim NewObject As SmApplic.ISmObject 'new sm object
Dim ClassId As Integer
Dim SmClass As ISmClass
Dim LinkObject As ISmObject
Dim RootObject As ISmObject
Dim MainObject As ISmObject
Dim LinkClassid As Integer
Dim Behavior As ISmBehavior
Dim SmAttributes As ISmClassAttributes
Dim SmAttribute As ISmClassAttribute
Dim Value As String
Dim Sequence As ISmSequence
Dim PrmIdAttrs As SmRecordList
Dim PrmIdRec As SmRecord
Dim FolderObj As ISmObject
Dim LinkAttribute As SmRecord
Dim Folder_ClassId As Integer
Dim SaveasDialog As ISmSaveAsDialog
Dim SmClass_1 As ISmClass
Dim SmClass_2 As ISmClass
Dim ChildClasses As ISmClasses
Dim MainClassObject As ISmObject
Dim Selected_Parent As ISmObject
Dim Parent_ClassId As Integer
Dim Parent_ObjectId As Integer
Dim Parent_Object As ISmObject
'下面这一句调不通,还有其他的问题。
Set SmClass = Session.MetaInfo.SmClassByName("SOLIDWORKS Assembly")
ClassId = SmClass.ClassId
' Create new SmObject
Set NewObject = Session.ObjectStore.NewObject(ClassId)
' Adds all object attributes to its data
NewObject.AddAllAttributes
NewObject.SetDefaultValues
Set SmAttributes = NewObject.SmClass.Attributes
Set SmAttribute = SmAttributes.ItemByIndex(2) 'CN_ID
Set Sequence = Session.ObjectStore.Sequences.ItemByAttribute(SmAttribute)
Value = Sequence.GetCurrentValue
Sequence.IncrementValue Value, True
Value = Sequence.GetCurrentValue
' Here you must assign values at least to mandatory , obligatory
' and primary attributes, otherwise an error message will appear
' on the Insert operation
' ...
NewObject.Data.Value("CN_ID") = Value
' Save object to the database
NewObject.Data.Value("CN_DESCRIPTION") = "SolidWorks Assembly_3"
NewObject.Data.Value("FILE_NAME") = "Mainclinchassm.sldasm"
NewObject.Data.Value("DIRECTORY") = "e:\api_training\solidworks"
LinkClassid = 0
NewObject.Insert
Set SmClass_1 = Session.MetaInfo.SmClassByName("SolidWorks Assembly")
Set SmClass_2 = Session.MetaInfo.SmClassByName("Documents")
Set ChildClasses = SmClass_2.AllChildClasses
'set MainClassObject as Project trees
Set MainClassObject = Session.ObjectStore.NewObject(1)
MainClassObject.ObjectId = -1
Set SaveasDialog = SmCommonGUI.Dialogs.NewSaveAsDialog
SaveasDialog.FileName = "Mainclinchassm.sldasm"
SaveasDialog.SelectedClass = SmClass_1
SaveasDialog.Classes = ChildClasses
SaveasDialog.SelectedMainClassObject = MainClassObject
SaveasDialog.ShowModal
If (SaveasDialog.ModalResult <> mrOK) Then
Exit Sub
End If
Set Selected_Parent = SaveasDialog.SelectedParent
 arent_ObjectId = Selected_Parent.ObjectId
 arent_ClassId = Selected_Parent.ClassId
If (Parent_ClassId = SmClass_2.ClassId) Then
Set MainClassObject = SaveasDialog.SelectedMainClassObject
 arent_ObjectId = MainClassObject.ObjectId
MsgBox Parent_ObjectId
 arent_ClassId = MainClassObject.ClassId
If ((Parent_ObjectId = -1) And (Parent_ClassId = 1)) Then
MsgBox "You should Select Projects!"
Exit Sub
End If
Set Parent_Object = Session.ObjectStore.RetrieveObject(Parent_ClassId, Parent_ObjectId)
NewObject.AddToDesktop Parent_Object, LinkClassid, LinkObject, RootObject
Else
Folder_ClassId = Session.MetaInfo.SmClassByName("Folder").ClassId
'ObjectId = Selected_Parent.ObjectId
If (Selected_Parent.ClassId <> Folder_ClassId) Then
MsgBox "You can't create the link "
Exit Sub
End If
LinkClassid = Session.MetaInfo.HierarchicalLinkClassByClasses(Selected_Parent.ClassId, NewObject.ClassId)
Set LinkObject = NewObject.LinkToParent(LinkClassid, Selected_Parent, LinkAttribute)
End If
End Sub
'下面代码我在窗体上建了一个按钮来调用的
Private Sub Command1_Click()
Call cmdLogin
Add_File3
End Sub
'感谢高手能帮帮忙,上面的的代码有不少问题,主要是有一些变量不懂的定义。 |