problem adding block with attribute
![]() 4/19/2021 11:12 AM
|
---|
Good morning, i've just updated my program with 4.0.38.256 from 4.0.34.100. when i create a model adding a block with attribute and try to open it with autocad, it tell me that there are many error in the file. pease note that it's the same code and block that i used with the previous edition and that works well. |
![]() 4/23/2021 11:05 AM
|
---|
Hi, Your cloning code was incorrect, it was defining the clone as from Model to Model, but it should be from ModelSorg (source model) to Model (target model). Below is how you should do the cloning: Visual Basic Code: Imports WW.Cad.Drawing Imports WW.Cad.IO Imports WW.Cad.Model Imports WW.Cad.Model.Entities Imports WW.Cad.Model.Tables Imports WW.Math Imports System.Drawing Imports System.Drawing.Printing Imports WW.Cad.Base Imports WW.Cad.Drawing.GDI Imports System.Environment Class MainWindow Private Sub Bt_Test_Click(sender As Object, e As RoutedEventArgs) Dim Model As New DxfModel(DxfVersion.Dxf14) Dim StileSTQ As DxfTextStyle = New DxfTextStyle("STQ", "arial.ttf") Model.TextStyles.Add(StileSTQ) If CB1.IsChecked Then AggiungiBlocco(Model, "A3_AI_PLUS.dwg", "A3_AI_PLUS") If CB2.IsChecked Then AggiungiBlocco(Model, "DatiPrin.dwg", "DatiPrin") Dim layer1 As New DxfLayer("A01") Model.Layers.Add(layer1) Dim Nfile As String = Environment.GetFolderPath(SpecialFolder.DesktopDirectory) & "\WW_Test2021.dwg" DwgWriter.Write(Nfile, Model) Dim boundsCalculator As New BoundsCalculator() boundsCalculator.GetBounds(Model) Dim bounds As Bounds3D = boundsCalculator.Bounds Dim active As DxfVPort = New DxfVPort(DxfVPort.ActiveVPortName) active.Height = bounds.Delta.Y active.AspectRatio = bounds.Delta.X / bounds.Delta.Y active.Center = bounds.Center Model.VPorts.Add(active) DwgWriter.Write(Nfile, Model) MsgBox("File created") End Sub Sub AggiungiBlocco(Model As DxfModel, NomeDis As String, NomeBlocco As String) Dim ModelSorg As DxfModel = WW.Cad.IO.DwgReader.Read(My.Application.Info.DirectoryPath & "\Resources\" & NomeDis) Dim cc As New CloneContext(ModelSorg, Model, ReferenceResolutionType.CloneMissing) For Each Ent In ModelSorg.Entities If Ent.EntityType <> "INSERT" Then Model.Entities.Add(Ent.Clone(cc)) Next Dim srcBlock As DxfBlock = ModelSorg.GetBlockWithName(NomeBlocco) Dim targetBlock As DxfBlock = srcBlock.Clone(cc) Model.Blocks.Add(targetBlock) cc.ResolveReferences() End Sub End Class - Wout |