Insert complete block (object) on position
Moderators: SDS, support, admin
Insert complete block (object) on position
Hello,
we must add two seperate blocks or objects from dxf-files in one new cad-image. Can help someone and give us some helpful ideas ?
Greatings Mike
we must add two seperate blocks or objects from dxf-files in one new cad-image. Can help someone and give us some helpful ideas ?
Greatings Mike
Re: Insert complete block (object) on position
Hello Mike,
It is necessary to do the following:
Sergey.
It is necessary to do the following:
- to find necessary block in a source file
- to get all its entities
- to create new block in a destination file
- to create new entities and add them to a new block in a destination file
- new entities must be equal to entities from the block of a source file
Code: Select all
private void btnAssignBlocks_Click(object sender, System.EventArgs e)
{
this.cadImage = new CADImage();
this.cadImage.UseDoubleBuffering = false;
this.cadImage.InitialNewImage();
SetLayList();
this.cadImage.LoadFromFile(@"c:\FileBlocksToBeInsertedIn.dxf");
SetCADImageOptions();
string fName = @"c:\FileBlocksToBeTakenFrom.dxf";
CADImage cadImageSource = CADImage.CreateImageByExtension(fName);
cadImageSource.LoadFromFile(fName);
for (int i=0;i<cadImageSource.CurrentLayout.Converter.GetCounts(CADImport.FaceModule.ConvSection.Entities);i++)
{
CADEntity entSource = cadImageSource.CurrentLayout.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Entities[i];
if (entSource is CADInsert)
{
CADInsert entInsert = entSource as CADInsert;
CADBlock bl1 = new CADBlock();
bl1.Name = entInsert.Block.Name;
bl1.Color = entInsert.Block.Color;
bl1.Visibility = true;
bl1.Visible = true;
for (int j=0;j<entInsert.Block.Count;j++)
{
CADEntity entInBlock = entInsert.Block.Entities[j];
Type tp = entInBlock.GetType();
CADEntity entity = (CADEntity)Activator.CreateInstance(tp);
entity.AssignEntity(entInBlock);
entity.Loaded(this.cadImage.Converter);
this.cadImage.Converter.OnCreate(entity);
bl1.AddEntity(entity);
}
this.cadImage.Converter.Blocks.Add(bl1);
this.cadImage.Converter.OnCreate(bl1);
this.cadImage.Converter.Loads(bl1);
CADInsert ins1 = new CADInsert();
ins1.Block = bl1;
ins1.Point = entInsert.Point;
ins1.Visibility = true;
this.cadImage.Converter.Entities.Add(ins1);
this.cadImage.Converter.OnCreate(ins1);
this.cadImage.Converter.Loads(ins1);
}
}
this.cadPictBox.Invalidate();
CADtoDXF exportImage = new CADtoDXF(cadImage);
exportImage.SaveToFile(@"c:\output.dxf");
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Insert complete block (object) on position
Thanks it's fine, but this is not the whole result I need.
Now I use the AddScaledDXF-Method für insert a complete DXF-File. So I don't think about the entitys of the unknown insert-File.
After insert I have an insert-entity with my own name. I can found it simple in the whole datas. That's ok.
But the next problem is: The rotation of the inserted object. I can placed it on needed position but only in rotation of one axis (i think it was the x-axis). I need a transformation of the object in x,y,z-position and in rotation from x,y,z-axis.
How can i do this ?
Now I use the AddScaledDXF-Method für insert a complete DXF-File. So I don't think about the entitys of the unknown insert-File.
After insert I have an insert-entity with my own name. I can found it simple in the whole datas. That's ok.
But the next problem is: The rotation of the inserted object. I can placed it on needed position but only in rotation of one axis (i think it was the x-axis). I need a transformation of the object in x,y,z-position and in rotation from x,y,z-axis.
How can i do this ?
Re: Insert complete block (object) on position
Hello!
Function AddScaledDXF returns TsgDXFInsert object. We recommend to use the following code:
Sergey.
Function AddScaledDXF returns TsgDXFInsert object. We recommend to use the following code:
Code: Select all
var
...
vIns: TsgDXFInsert;
begin
...
vIns := TsgDXFInsert(TsgDXFImage.AddScaledDXFEx(...);
vIns.Extrusion := MakeFPoint(0.577, 0.577, 0.577);// Insert contains Block with XREF
TsgDXFImage.Converter.Loads(vIns);
TsgDXFImage.GetExtents;
...
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Insert complete block (object) on position
What class is TsgDXFInsert ??
I can't find it.
I can't find it.
Re: Insert complete block (object) on position
Sorry, we gave you code for Delphi. Please try the following (it is based on Viewer demo):
Sergey.
Code: Select all
private void btnAddScaledDXF_Extrusion_Click(object sender, System.EventArgs e)
{
CADInsert entInsert;
if(this.cadImage == null) return;
this.cadImage.UseDoubleBuffering = false;
CADImage aFile = new CADImage();
aFile.LoadFromFile(@"c:\Test.dxf");
this.cadImage.AddScaledDXF(aFile, "c:\\Test.dxf", new DPoint(200,0,0), new DPoint(1,1,1), 0);
for (int i=0;i<this.cadImage.Converter.GetCounts(CADImport.ConvSection.Entities);i++)
{
if (this.cadImage.Converter.GetSection(CADImport.ConvSection.Entities).Entities[i] is CADInsert)
{
entInsert = (CADInsert)this.cadImage.Converter.GetSection(CADImport.ConvSection.Entities).Entities[i];
if (entInsert.Block.Name == "c:\\Test.dxf")
{
CADImport.DPoint nPoint = new DPoint(0.577, 0.577, 0.577);
entInsert.Extrusion = new DPoint(0.577, 0.577, 0.577);
this.cadImage.Converter.Loads(entInsert);
}
}
}
this.DoResize();
}
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support
Re: Insert complete block (object) on position
I converted in vb.net the first example, but I have an error on:
Dim entInsert As CADInsert = entSource
entSource in c CADLine type, the error message is: "Cast error, cannot convert CADLine to CADInsert"
somebody know how to insert a dwg block into a dwg file?
thanks
here is it all the code:
Me.cadImage = New CADImage()
Me.cadImage.UseDoubleBuffering = False
Me.cadImage.InitialNewImage()
SetLayList()
Me.cadImage.LoadFromFile("c:\file1.dwg")
SetCADImageOptions()
Dim fName As String = "c:\block1.dwg"
Dim cadImageSource As CADImage = cadImage.CreateImageByExtension(fName)
cadImageSource.LoadFromFile(fName)
Dim i As Integer
For i = 0 To cadImageSource.CurrentLayout.Converter.GetCounts(CADImport.FaceModule.ConvSection.Entities)
Dim entSource As CADEntity = cadImageSource.CurrentLayout.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Entities.Item(i)
'If entSource Is CADInsert Then '<-does'nt work in vb.net
'Dim entInsert As CADInsert = entSource
Dim entInsert As CADInsert = entSource
Dim bl1 As New CADBlock()
bl1.Name = entInsert.Block.Name
bl1.Color = entInsert.Block.Color
bl1.Visibility = True
bl1.Visible = True
Dim j As Integer
For j = 0 To entInsert.Block.Count
Dim entInBlock As CADEntity = entInsert.Block.Entities(j)
Dim tp As Type = entInBlock.GetType()
Dim entity As CADEntity = Activator.CreateInstance(tp)
entity.AssignEntity(entInBlock)
entity.Loaded(Me.cadImage.Converter)
Me.cadImage.Converter.OnCreate(entity)
bl1.AddEntity(entity)
Next j
Me.cadImage.Converter.Blocks.Add(bl1)
Me.cadImage.Converter.OnCreate(bl1)
Me.cadImage.Converter.Loads(bl1)
Dim ins1 As New CADInsert()
ins1.Block = bl1
ins1.Point = entInsert.Point
ins1.Visibility = True
Me.cadImage.Converter.Entities.Add(ins1)
Me.cadImage.Converter.OnCreate(ins1)
Me.cadImage.Converter.Loads(ins1)
'End If 'If entSource Is CADInsert Then
Next i
Me.cadPictBox.Invalidate()
Dim exportImage As New CADtoDXF(cadImage)
exportImage.SaveToFile("c:\temp\output.dxf")
Dim entInsert As CADInsert = entSource
entSource in c CADLine type, the error message is: "Cast error, cannot convert CADLine to CADInsert"
somebody know how to insert a dwg block into a dwg file?
thanks
here is it all the code:
Me.cadImage = New CADImage()
Me.cadImage.UseDoubleBuffering = False
Me.cadImage.InitialNewImage()
SetLayList()
Me.cadImage.LoadFromFile("c:\file1.dwg")
SetCADImageOptions()
Dim fName As String = "c:\block1.dwg"
Dim cadImageSource As CADImage = cadImage.CreateImageByExtension(fName)
cadImageSource.LoadFromFile(fName)
Dim i As Integer
For i = 0 To cadImageSource.CurrentLayout.Converter.GetCounts(CADImport.FaceModule.ConvSection.Entities)
Dim entSource As CADEntity = cadImageSource.CurrentLayout.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Entities.Item(i)
'If entSource Is CADInsert Then '<-does'nt work in vb.net
'Dim entInsert As CADInsert = entSource
Dim entInsert As CADInsert = entSource
Dim bl1 As New CADBlock()
bl1.Name = entInsert.Block.Name
bl1.Color = entInsert.Block.Color
bl1.Visibility = True
bl1.Visible = True
Dim j As Integer
For j = 0 To entInsert.Block.Count
Dim entInBlock As CADEntity = entInsert.Block.Entities(j)
Dim tp As Type = entInBlock.GetType()
Dim entity As CADEntity = Activator.CreateInstance(tp)
entity.AssignEntity(entInBlock)
entity.Loaded(Me.cadImage.Converter)
Me.cadImage.Converter.OnCreate(entity)
bl1.AddEntity(entity)
Next j
Me.cadImage.Converter.Blocks.Add(bl1)
Me.cadImage.Converter.OnCreate(bl1)
Me.cadImage.Converter.Loads(bl1)
Dim ins1 As New CADInsert()
ins1.Block = bl1
ins1.Point = entInsert.Point
ins1.Visibility = True
Me.cadImage.Converter.Entities.Add(ins1)
Me.cadImage.Converter.OnCreate(ins1)
Me.cadImage.Converter.Loads(ins1)
'End If 'If entSource Is CADInsert Then
Next i
Me.cadPictBox.Invalidate()
Dim exportImage As New CADtoDXF(cadImage)
exportImage.SaveToFile("c:\temp\output.dxf")
Re: Insert complete block (object) on position
Hello!
Please try the followin code:
Sergey.
Please try the followin code:
Code: Select all
Private Sub btnAssignBlocks_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssignBlocks.Click
Dim I, J As Integer
Me.cadImage = New CADImage
Me.cadImage.UseDoubleBuffering = False
Me.cadImage.InitialNewImage()
SetLayList()
Me.cadImage.LoadFromFile("c:\FileBlocksToBeInsertedIn.dxf")
SetCADImageOptions()
Dim fName As String = "c:\FileBlocksToBeTakenFrom.dxf"
Dim cadImageSource As CADImage = cadImage.CreateImageByExtension(fName)
cadImageSource.LoadFromFile(fName)
For I = 0 To cadImageSource.CurrentLayout.Converter.GetCounts(CADImport.FaceModule.ConvSection.Entities) - 1
Dim entSource As CADEntity = cadImageSource.CurrentLayout.Converter.GetSection(CADImport.FaceModule.ConvSection.Entities).Entities(I)
If (TypeOf entSource Is CADInsert) Then
Dim entInsert As CADInsert = entSource
Dim bl1 As CADBlock = New CADBlock
bl1.Name = entInsert.Block.Name
bl1.Color = entInsert.Block.Color
bl1.Visibility = True
bl1.Visible = True
For J = 0 To entInsert.Block.Count - 1
Dim entInBlock As CADEntity = entInsert.Block.Entities(J)
Dim tp As Type = entInBlock.GetType()
Dim entity As CADEntity = Activator.CreateInstance(tp)
entity.AssignEntity(entInBlock)
entity.Loaded(Me.cadImage.Converter)
Me.cadImage.Converter.OnCreate(entity)
bl1.AddEntity(entity)
Next J
Me.cadImage.Converter.Blocks.Add(bl1)
Me.cadImage.Converter.OnCreate(bl1)
Me.cadImage.Converter.Loads(bl1)
Dim ins1 As CADInsert = New CADInsert
ins1.Block = bl1
ins1.Point = entInsert.Point
ins1.Visibility = True
Me.cadImage.Converter.Entities.Add(ins1)
Me.cadImage.Converter.OnCreate(ins1)
Me.cadImage.Converter.Loads(ins1)
End If
Next I
Me.cadPictBox.Invalidate()
Dim exportImage As CADtoDXF = New CADtoDXF(cadImage)
exportImage.SaveToFile("c:\output.dxf")
End Sub
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support
Chat support on Skype: cadsofttools.support