Sheet.AddBorder System.ArgumentException: 'The parameter is incorrect. (0x80070057 (E_INVALIDARG))'

Sheet.AddBorder System.ArgumentException: 'The parameter is incorrect. (0x80070057 (E_INVALIDARG))'

mowag
Enthusiast Enthusiast
397 Views
3 Replies
Message 1 of 4

Sheet.AddBorder System.ArgumentException: 'The parameter is incorrect. (0x80070057 (E_INVALIDARG))'

mowag
Enthusiast
Enthusiast

Hi,

 

i ' harvested' all the Borderdefinitions from a 'root' drawing.

i'm trying to replace a border in an .idw with a  Border generated from one of the 'harvested' Borderdefinitons, but i get a E_INVALIDARG error  on sheet.AddBorder(borderdefinition) in PlaceWatermark ??

 

        Dictionary<int,Inventor.BorderDefinition> BorderDefinitionDictionary { get; set; }

 

        public void HarvestBorders(string drawingfullpath)
        {
            Inventor.DrawingDocument oDrawDoc;
            oDrawDoc = (Inventor.DrawingDocument)_inventordataService.invApp.Documents.Open(drawingfullpath, false);
            foreach (Inventor.BorderDefinition borderdef in oDrawDoc.BorderDefinitions)
            {
                BorderList.Add(borderdef);
                string[] chuncks = borderdef.Name.Split('-');  
                if (chuncks.Contains("A4") && chuncks.Contains("Landscape")) BorderDefinitionDictionary.Add(1, borderdef);
                if (chuncks.Contains("A4") && chuncks.Contains("Portrait")) BorderDefinitionDictionary.Add(2, borderdef);
                if (chuncks.Contains("A3") && chuncks.Contains("Landscape")) BorderDefinitionDictionary.Add(3, borderdef);
                if (chuncks.Contains("A3") && chuncks.Contains("Portrait")) BorderDefinitionDictionary.Add(4, borderdef);
                if (chuncks.Contains("A2") && chuncks.Contains("Landscape")) BorderDefinitionDictionary.Add(5, borderdef);
                if (chuncks.Contains("A2") && chuncks.Contains("Portrait")) BorderDefinitionDictionary.Add(6, borderdef);
                if (chuncks.Contains("A1") && chuncks.Contains("Landscape")) BorderDefinitionDictionary.Add(7, borderdef);
                if (chuncks.Contains("A1") && chuncks.Contains("Portrait")) BorderDefinitionDictionary.Add(8, borderdef);
                if (chuncks.Contains("A0") && chuncks.Contains("Landscape")) BorderDefinitionDictionary.Add(9, borderdef);
                if (chuncks.Contains("A0") && chuncks.Contains("Portrait")) BorderDefinitionDictionary.Add(10, borderdef);
            }

        }
        public void PlaceWatermark(string FullPathDrawing)
        {
            string or = string.Empty;
            string si = string.Empty;
            Inventor.DrawingDocument oDrawDoc = null;
            Inventor.DrawingSheetSizeEnum size;
            Inventor.PageOrientationTypeEnum orientation;

            oDrawDoc = (Inventor.DrawingDocument)_inventordataService.invApp.Documents.Open(FullPathDrawing, false);

            Inventor.Sheet Sheet = oDrawDoc.ActiveSheet;
            orientation = Sheet.Orientation;
            size = Sheet.Size;

            switch (orientation)
            {
                case PageOrientationTypeEnum.kLandscapePageOrientation:
                    or = "Landscape";
                    break;
                case PageOrientationTypeEnum.kPortraitPageOrientation:
                    or = "Portrait";
                    break;

                default:
                    break;
            }

            switch (size)
            {
                case DrawingSheetSizeEnum.kA4DrawingSheetSize:
                    si = "A4";
                    break;
                case DrawingSheetSizeEnum.kA3DrawingSheetSize:
                    si = "A3";
                    break;
                case DrawingSheetSizeEnum.kA2DrawingSheetSize:
                    si = "A2";
                    break;

                case DrawingSheetSizeEnum.kA1DrawingSheetSize:
                    si = "A1";
                    break;

                case DrawingSheetSizeEnum.kA0DrawingSheetSize:
                    si = "A0";
                    break;
            }



            // Iterate over all sheets in the Drawing
            foreach (Inventor.Sheet sheet in oDrawDoc.Sheets)
            {
                sheet.Activate();

                Inventor.BorderDefinition borderdefinition = null;

                if (si == "A4" && or == "Landscape") borderdefinition = BorderDefinitionDictionary[1];
                if (si == "A4" && or == "Portrait")  borderdefinition = BorderDefinitionDictionary[2];
                if (si == "A3" && or == "Landscape") borderdefinition = BorderDefinitionDictionary[3];
                if (si == "A3" && or == "Portrait")  borderdefinition = BorderDefinitionDictionary[4];
                if (si == "A2" && or == "Landscape") borderdefinition = BorderDefinitionDictionary[5];
                if (si == "A2" && or == "Portrait")  borderdefinition = BorderDefinitionDictionary[6];
                if (si == "A1" && or == "Landscape") borderdefinition = BorderDefinitionDictionary[7];
                if (si == "A1" && or == "Portrait")  borderdefinition = BorderDefinitionDictionary[8];
                if (si == "A0" && or == "Landscape") borderdefinition = BorderDefinitionDictionary[9];
                if (si == "A0" && or == "Portrait")  borderdefinition = BorderDefinitionDictionary[10];


                sheet.Border.Delete();
                sheet.AddBorder(borderdefinition);

                oDrawDoc.Save();
            }

 

0 Likes
Accepted solutions (2)
398 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor
Accepted solution

Hi @mowag.  I am not good with C#, so it is difficult for me to proofread your code example.  However, I would suggest looking into the following things:

  • I would suggest adding some code to check if your variable 'borderdefinition' has a value, before trying to use it to change the border of the sheet.  And if it has no value, maybe log some feedback about it, so you know you are encountering that specific issue.
  • Does the border definition contain any prompted entries?  It is likely not common for borders to contain prompted entries, but it is possible, and there is an optional second input for providing their values within the Sheet.AddBorder Method.  If the border definition does have some prompted entries, then you would need to provide input for them, even if you do not care about their values, in the form of an Array of Strings with the same number of elements as the number of prompted entries.
  • It says that we can either provide a BorderDefinition object directly, or we can just provide the name (a String) of the BorderDefinition, so you could explore just providing its name, instead of the BorderDefinition object, if it is easier for you.
  • Also, I noticed that you seem to be using something like a List(Of BorderDefinition) (your variable named 'BorderList'), and also a Dictionary(Of Int, BorderDefinition) to capture the border definitions.  Well, that may not be good enough.  You will need to actually copy those BorderDefinitions from the 'source' document to the 'destination' document, before you can use any of them to add a border to the 'destination' document which is based on one of them.  You can not just capture them from the 'source' document into a List or Dictionary, then use them in the 'destination' document directly.  The BorderDefinition must already exist within the destination document before the destination document can use it.

Just some thoughts

Edit:  You can use the BorderDefinition.CopyTo Method to copy the source drawing's BorderDefinition objects to the destination drawing document.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

Frederick_Law
Mentor
Mentor
Accepted solution

Need to add border (titleblock, sketch symbol, sheet format) to the drawing before using it in sheet.

They should show in "Drawing Resources".

0 Likes
Message 4 of 4

mowag
Enthusiast
Enthusiast

Hi WCrihfield and Frederick_Law,

 

Problem was ideed that the Borderdefinitions were not copied into the .idw before using them !

Thanks alot for the help !

 

Johan

0 Likes