Change an XRef

Discuss and ask questions about CAD .NET library.

Moderators: SDS, support, admin

Post Reply
SoupMan
Posts: 7
Joined: 05 Jan 2010, 18:30

Change an XRef

Post by SoupMan » 26 May 2011, 01:54

Hi,

I noticed that under CADImage.Converter you have XRefs. Is there a way to change the XRef?

See code attempt:

Code: Select all

            this.cadEditorControl1.Image.Converter.XRefs[0].Dispose();
            CADXRef NewXRef = new CADXRef();            
            NewXRef.AddCADImage(@"Z:\MFG\WF\MYXREF.DWG");
            this.cadEditorControl1.Image.Converter.XRefs.Add(NewXRef);
            this.cadEditorControl1.Image.Converter.Loads(NewXRef);
            this.cadEditorControl1.Invalidate();
            this.cadEditorControl1.Refresh();
Objective:
We have a standard template that is used for most drawings but under some circumstances we need to change this template. The simple solution is to change the XRef on the fly. Can this be done?

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Change an XRef

Post by support » 26 May 2011, 12:54

Hello.
Changing an XRef object isn't correct. Correct method for your task is deleting XRef as well as insert and block representing it then adding a new XREf using vethod AddScaledDXF:

Code: Select all

            CADEntityCollection ec = cadImage.Converter.XRefs;
            string nm = null;

            for (int i = 0; i < ec.Count; i++)
                if (((CADXRef)ec[i]).Name == "name")
                {
                    nm = ((CADXRef)ec[i]).Name;
                    ec.RemoveAt(i);
                }

            ec = cadImage.Converter.Entities;
            for (int i = 0; i < ec.Count; i++)
                if ((ec[i].EntType == EntityType.Insert) && (((CADInsert)ec[i]).Block.Name == nm))
                    ec.RemoveAt(i);

            ec = cadImage.Converter.Blocks;
            for (int i = 0; i < ec.Count; i++)
                if (((CADBlock)ec[i]).Name == nm)
                    ec.RemoveAt(i);

            CADImage img = CADImage.CreateImageByExtension(filename);
            img.LoadFromFile(filename);
            cadImage.AddScaledDXF(img, filename, new DPoint(0, 0, 0), new DPoint(1, 1, 1), 0);

            cadImage.GetExtents();
Alexander.
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

SoupMan
Posts: 7
Joined: 05 Jan 2010, 18:30

Re: Change an XRef

Post by SoupMan » 26 May 2011, 22:41

Thanks.

That did exactly what I wanted it to do. I have limited knowledge of Autocad so some things like this aren't obvious to me.

dor_r@top-s.co.il
Posts: 8
Joined: 17 Jan 2017, 17:58

Re: Change an XRef

Post by dor_r@top-s.co.il » 09 Feb 2017, 12:11

But is there a way to add the new file to the exact location, rotation etc of the original xref (before deletion)?

Dror

sertaliano
Posts: 1
Joined: 27 Oct 2023, 20:02

Re: Change an XRef

Post by sertaliano » 27 Oct 2023, 20:04

And what about saving a base file? How?
And how to delete references, if xrefs is not loaded?
Last edited by sertaliano on 27 Oct 2023, 20:07, edited 1 time in total.

support
Posts: 3271
Joined: 30 Mar 2005, 11:36
Contact:

Re: Change an XRef

Post by support » 31 Oct 2023, 15:59

Hi!

XRefs are not deleted if there are some inserts with blocks into the XRef blocks.
Сall on an empty file and find out what is being created:
insert → block → xref.

Kind regards,
Suraya
Technical Support E-mail: support@cadsofttools.com
Chat support on Skype: cadsofttools.support

Post Reply