乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 63|回复: 4

GstarCAD Api : WblockCloneObjects

[复制链接]

9

主题

30

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
66
发表于 2015-11-10 12:32:58 | 显示全部楼层 |阅读模式
您好,
我对这段代码有问题:
  1.     Public Sub teste()
  2.         Dim ofd As New OpenFileDialog
  3.         If Not ofd.ShowDialog Then Exit Sub
  4.         Dim layoutTemplate As String = "MODELO_A4"
  5.         Dim layoutName As String = "NOVO_LAYOUT"
  6.         Dim handleBlocoCarimbo As String = "D66"
  7.         Dim handleMainViewPort As String = "C0E"
  8.         Dim handleLayoutViewPort As String = "C13"
  9.         Dim doc = ApplicationServices.Application.DocumentManager.MdiActiveDocument
  10.         Using tr = doc.TransactionManager.StartTransaction
  11.             Using dbOrig As New Database(False, True)
  12.                 dbOrig.ReadDwgFile(ofd.FileName, FileShare.Read, True, "")
  13.                 'Make the original database the working database
  14.                 HostApplicationServices.WorkingDatabase = dbOrig
  15.                 Using trOrig As Transaction = dbOrig.TransactionManager.StartTransaction()
  16.                     ' Get the dictionary of the original database
  17.                     Dim lytDict As DBDictionary = trOrig.GetObject(dbOrig.LayoutDictionaryId, ForRead)
  18.                     'Get the layout in the original database
  19.                     Dim lytMgr As LayoutManager = LayoutManager.Current()
  20.                     Dim layoutId As ObjectId = lytMgr.GetLayoutId(layoutTemplate)
  21.                     Dim layout As Layout = trOrig.GetObject(layoutId, ForRead)
  22.                     'Get the block table record of the existing layout
  23.                     Dim blkTableRec As BlockTableRecord = trOrig.GetObject(layout.BlockTableRecordId, ForRead)
  24.                     'Get the object ids of the objects in the existing block table record
  25.                     Dim objIdCol As New ObjectIdCollection()
  26.                     For Each objId As ObjectId In blkTableRec
  27.                         objIdCol.Add(objId)
  28.                     Next
  29.                     'return to original WorkingDatabase
  30.                     HostApplicationServices.WorkingDatabase = doc.Database
  31.                     ' Clone the objects to the new layout
  32.                     Dim newLytMgr As LayoutManager = LayoutManager.Current()
  33.                     If newLytMgr.GetLayoutId(layoutName).IsValid Then
  34.                         newLytMgr.DeleteLayout(layoutName)
  35.                     End If
  36.                     Dim newLayoutId As ObjectId = newLytMgr.CreateLayout(layoutName)
  37.                     Dim newLayout As Layout = newLayoutId.GetObject(OpenMode.ForWrite)
  38.                     newLayout.CopyFrom(layout)
  39.                     Dim idMap As New IdMapping()
  40.                     doc.Database.WblockCloneObjects(objIdCol,
  41.                                               newLayout.BlockTableRecordId,
  42.                                               idMap,
  43.                                               DuplicateRecordCloning.Ignore,
  44.                                               False)
  45.                     'define block attributes
  46.                     Dim bid As ObjectId = HandleToObjectID(dbOrig, handleBlocoCarimbo)
  47.                     Dim bref As BlockReference = idMap(bid).Value.GetObject(ForWrite)
  48.                     If bref Is Nothing Then
  49.                         MsgBox("error, bref is nothing")
  50.                         Exit Sub
  51.                     End If
  52.                     For Each attid As ObjectId In bref.AttributeCollection
  53.                         Dim attref As AttributeReference = attid.GetObject(ForWrite)
  54.                         attref.TextString = "teste"
  55.                     Next
  56.                     'define viewport center
  57.                     Dim vp As Viewport = idMap(HandleToObjectID(dbOrig, handleLayoutViewPort)).Value.GetObject(ForWrite)
  58.                     vp.ViewCenter = New Point2d(0, 0)
  59.                     vp.ViewTarget = Point3d.Origin 'para o viewcenter funcionar
  60.                     'zoom extents no bloco do carimbo
  61.                     vp = idMap(HandleToObjectID(dbOrig, handleMainViewPort)).Value.GetObject(ForWrite)
  62.                     With bref.GeometricExtents
  63.                         vp.ViewCenter = New Point2d((.MaxPoint.X + .MinPoint.X) / 2, (.MaxPoint.Y + .MinPoint.Y) / 2)
  64.                         vp.ViewTarget = Point3d.Origin 'para o viewcenter funcionar
  65.                         vp.ViewHeight = .MaxPoint.Y - .MinPoint.Y
  66.                     End With
  67.                 End Using 'trOrig
  68.             End Using 'dbOrig  
  69.             If layoutName IsNot Nothing Then
  70.                 LayoutManager.Current.CurrentLayout = layoutName
  71.                 LayoutManager.Current.CurrentLayout = "Model"
  72.             End If
  73.         End Using
  74.     End Sub
  75. Public Function HandleToObjectID(db As Database, ByVal h As String) As ObjectId
  76.         Try
  77.             Dim num As Long = Long.Parse(h, Globalization.NumberStyles.HexNumber)
  78.             Dim id As ObjectId = db.GetObjectId(False, New Handle(num), 0)
  79.             If id.IsErased Then Return ObjectId.Null
  80.             Return id
  81.         Catch
  82.             Return ObjectId.Null
  83.         End Try
  84.     End Function

运行它,选择附加DWT
它应该在当前图形中创建一个新布局,并将其插入设计“MODELOS.dwt”中现有布局的副本
中,但它不识别到原始布局中的块的映射
缺少什么?

本帖以下内容被隐藏保护;需要你回复后,才能看到!

游客,如果您要查看本帖隐藏内容请回复
回复

使用道具 举报

170

主题

1424

帖子

8

银币

顶梁支柱

Rank: 50Rank: 50

铜币
2119
发表于 2015-11-10 17:36:15 | 显示全部楼层
不确定您是否先将模板块添加到块中,然后再将其添加到图纸空间中(这对我来说很有效)。
对于新图纸,我归档。副本(sTemplate,sPath);将模板复制到具有新名称的新文件夹中
回复

使用道具 举报

9

主题

30

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
66
发表于 2015-11-11 06:59:06 | 显示全部楼层
工作流程如下:
1)在模型空间中有一个细分的批次
2)在每个布局中将是每个批次的叶子
3)调用一个命令,要求选择一个包含布局模型的DWT
4)然后该命令使用布局模型创建各种布局。这个模型必须包含一个带有属性的块和一个视口。
5)命令将视口集中在批次的形心中,并填充块的属性
这个流程在AutoCAD中运行良好,显示的代码。
问题出在GstarCAD中,做“Wblock CloneObject”显然不是克隆一切,包括给出致命错误并关闭GstarCAD
回复

使用道具 举报

51

主题

613

帖子

9

银币

中流砥柱

Rank: 25

铜币
815
发表于 2015-11-11 08:34:01 | 显示全部楼层
如果它在AutoCAD中正常工作,我的建议是联系support@gstarcad.net
回复

使用道具 举报

9

主题

30

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
66
发表于 2015-11-11 09:04:48 | 显示全部楼层
我已经这样做了
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-4 21:54 , Processed in 0.196013 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表