Error in Revit 2018 DWG Import

Error in Revit 2018 DWG Import

AnatolyCEL
Enthusiast Enthusiast
1,270 Views
5 Replies
Message 1 of 6

Error in Revit 2018 DWG Import

AnatolyCEL
Enthusiast
Enthusiast

Problem in Revit 2018. Document.Import Method (String, DWGImportOptions, View, ElementId)

 

Application imports DWG files to Revit that way:

 

 

            DWGImportOptions dWGImportOptions = new DWGImportOptions
            {
                ThisViewOnly = true,
                ColorMode = ImportColorMode.BlackAndWhite,
                VisibleLayersOnly = true,
                Unit = ImportUnit.Default,
                Placement = ImportPlacement.Origin,
                OrientToView = true
            };

 

 

next load Line Weights file:

IList<int> lineWeights = new List<int>();
                using (FileStream fileStream = new FileStream(lineWeightsPath,  FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                using (StreamReader streamReader = new StreamReader(fileStream))
                {
                    string line;
                    while ((line = streamReader.ReadLine()) != null)
                    {
                        int intLine;
                        if (int.TryParse(line, out intLine))
                            lineWeights.Add(intLine);
                    }
                    streamReader.Close();
                }

dWGImportOptions.SetLineWeights(lineWeights);

loaded file is attached.

 

Finally Import:

document.Import(pathDWG, dWGImportOptions, viewPlan, out elementId)

In Revit 2015...2017 works fine, but the same code in Revit 2018 rise exception:

 

"The array of line weights is not valid; either it contains less than expected 255 values, or one or more values are out of range 1 to 16
Parameter name: options"

 

I reality array contains 255 values, all of them in range 1 to 16. If try import manually (in Revit user interface) using the same file, works fine.

Error happens when import by application doing.

0 Likes
Accepted solutions (1)
1,271 Views
5 Replies
Replies (5)
Message 2 of 6

FAIR59
Advisor
Advisor

in the while-loop you have to skip the lines starting with #

0 Likes
Message 3 of 6

AnatolyCEL
Enthusiast
Enthusiast

if (int.TryParse(line, out intLine)) in my code. So line starting # is ignored. In addition, in debugger I watch resulted IList<int>, it's perfect

0 Likes
Message 4 of 6

FAIR59
Advisor
Advisor

I tested the import and get the same result. But binairy speaking is 255 entries a strange value. So I added a extra item (1) to the list, and then the import was a success. So the question is, should you add an item at the beginning or at the end.

 

Revit 2016 also accepts a list of 256 entries.

0 Likes
Message 5 of 6

AnatolyCEL
Enthusiast
Enthusiast

I hope it's temporary solution. If open this file by Revit user interface (Insert -> Import Line Weights) and just press OK, added before extra line ("1") is removed and import by application doesn't work again. This problem appears in Revit 2018 only! I think it's Error.

0 Likes
Message 6 of 6

FAIR59
Advisor
Advisor
Accepted solution
0 Likes