hi anyone!
I wanna create file and replace text in many drawings at the same time via C#. Does anyone help me to do that! thanks in advance. I did that but the result doesn't good.
phat
|
|
|
hi anyone!
I wanna create file and replace text in many drawings at the same time via C#. Does anyone help me to do that! thanks in advance. I did that but the result doesn't good.
phat
Maybe if you post the code you have, then others can help you optimize it.
Hi T.Willey,
here is my code
private void button1_Click(object sender, EventArgs e)
{
CAD.AcadDocument dx01 = null;
acad = new CAD.AcadApplication();
acad.Visible = true;
for (int i = 0; i < listBox1.Items.Count; i++)
{
dx01 = acad.Documents.Open(listBox1.Items[i].ToString(), true, null);
dx01 = acad.ActiveDocument;
CAD.AcadSelectionSets objSelCol = dx01.SelectionSets;
foreach (CAD.AcadSelectionSet objSelSet in objSelCol)
{
if (objSelSet.Name == "ISSUED FOR APPROVAL")
{
objSelSet.Name = "ISSUED FOR CONSTRUCTION";
}
}
dx01.Save();
dx01.Close(false, null);
}
---> I have so many drawings contain "ISSUED FOR APPROVAL", and I want to change into "ISSUED FOR CONSTRUCTION"
---> My problem is the objSelCol.count = 0. So., there is nothing change in my drawings.
thanks alots.
So are you running this from outside Acad? If so, I have no experience, and I hear it is slow that way. If you can run it from within Acad then it will be faster.
You can open a drawings database without opening the drawing in the editor, which will make it run a lot faster, but you can't use ' ssget ', because that is based off the document and not the database, I think. But even so, you can mimic what the ' ssget ' is doing. All you have to do is search each layout for the object type(s) you want, and then see if the string value has the string you want within. If so change it, and note that you changed it, so that you know to save the drawing.
If the text will be nested within a block, then just step through the block table, and search each one to see if it contains an object with the string desired to change. The layouts are defined as blocks, so by searching all records in the block table, you will search all the layouts also. This may be the direction you want to go, but you only need to go this way if you think the string can be nested within a block.
Does this sound like something you can do? Or do you need more guidance?