找回密码 注册 QQ登录
开思网工业级高精度在线3D打印服务

iCAx开思网

CAD/CAM/CAE/设计/模具 高清视频【积分说明】如何快速获得积分?快速3D打印 手板模型CNC加工服务在线3D打印服务,上传模型,自动报价
查看: 17969|回复: 5
打印 上一主题 下一主题

mwd121,有空的话帮我看看下面的代码。

[复制链接]
跳转到指定楼层
1
发表于 2004-5-3 00:12:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多同行朋友,交流,分享,学习。

您需要 登录 才可以下载或查看,没有帐号?注册

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
   &nbsparent_ObjectId = Selected_Parent.ObjectId
   &nbsparent_ClassId = Selected_Parent.ClassId
    
    If (Parent_ClassId = SmClass_2.ClassId) Then
       Set MainClassObject = SaveasDialog.SelectedMainClassObject
      &nbsparent_ObjectId = MainClassObject.ObjectId
       MsgBox Parent_ObjectId
      &nbsparent_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
'感谢高手能帮帮忙,上面的的代码有不少问题,主要是有一些变量不懂的定义。
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 赞一下!赞一下!
2
发表于 2004-5-3 09:58:50 | 只看该作者
看不懂,好难:(
3
发表于 2004-5-3 15:54:24 | 只看该作者
我还加我以下全局变量,
Option Explicit
Dim Session As SmApplic.SmSession
Dim GUIService As SmGUISrv.SmGUIServices
  
Dim Engine As SmEngine
Dim SmCommonGUI As SmCommonGUI
Dim GuiStore As ISmGUIStore
这样以后 Set SmClass = Session.MetaInfo.SmClassByName("SolidWorks Assembly")  
能通过编译了,但我在操作的时候SmarTeam告诉我无法建立连接。
我的代码要实现的功能事要实现把一个文本文件存到SmarTeam的库里面去,麻烦高手帮我调一下。我是用VB做的
4
发表于 2004-5-5 17:17:11 | 只看该作者
我将你的程序试了一下,没有问题!你再看一下,注意类名是否正确!
你的程序需要增加生命周期操作才能将文件真正地检入电子仓库,否则只是建立了一个数据库对象罢了!
5
发表于 2004-5-6 01:33:23 | 只看该作者
谢谢,我再分析试试
6
发表于 2006-12-25 10:22:49 | 只看该作者
直接用存放电子仓库的方法试试
您需要登录后才可以回帖 登录 | 注册

本版积分规则

3D打印手板模型快速制作服务,在线报价下单!

QQ 咨询|手机版|联系我们|iCAx开思网  

GMT+8, 2024-12-23 10:38 , Processed in 0.035428 second(s), 13 queries , Gzip On, Redis On.

Powered by Discuz! X3.3

© 2002-2024 www.iCAx.org

快速回复 返回顶部 返回列表