Page 1 of 1

Change an XRef

Posted: 26 May 2011, 01:54
by SoupMan
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?

Re: Change an XRef

Posted: 26 May 2011, 12:54
by support
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.

Re: Change an XRef

Posted: 26 May 2011, 22:41
by SoupMan
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.

Re: Change an XRef

Posted: 09 Feb 2017, 12:11
by dor_r@top-s.co.il
But is there a way to add the new file to the exact location, rotation etc of the original xref (before deletion)?

Dror

Re: Change an XRef

Posted: 27 Oct 2023, 20:04
by sertaliano
And what about saving a base file? How?
And how to delete references, if xrefs is not loaded?

Re: Change an XRef

Posted: 31 Oct 2023, 15:59
by support
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