70001950 Correct object properties that are Infinity or NaN double values

Article 70001950
Type HowTo
Product Converter
Version 8006
Date Added 4/1/2021 12:00:00 AM
Fixed 9.9001.0.5 (4/1/2021 12:00:00 AM)
Submitted by Luca Mancusi


Correct object properties that are Infinity or NaN double values


For some reason in the drawing may exist object with double properties that are Infinity or NaN
This may produce many problems to a drawing like saving or selecting
In the following example check all the polylines in the drawing that have invalid property for StartTangent and EndTangent

Use the following code before export the drawing in Dwg format

//check if a double value is a valid number
static bool IsdoubleValid(double d)
return !(double.IsNaN(d) && !double.IsInfinity(d));
//check if a Vector x,y,z are valid numbers
static bool IsValidVector(Vector v)
return IsdoubleValid(v.x) && IsdoubleValid(v.y) && IsdoubleValid(v.z);

document.UndoHistory.PushEnable(false);//force disable the undo history .Changes of polylines wrong properties does not need to be saved to undo history
vdPrimariesList primaries = document.GetPrimaries(true);//get all entities in the drawing in all layouts and all blocks
foreach (vdPrimary item in primaries)
vdPolyline pl = item as vdPolyline;
if (pl == null) continue;
if (pl.StartTangent != null && !IsValidVector(pl.StartTangent)) pl.StartTangent = null;
if (pl.EndTangent != null && !IsValidVector(pl.EndTangent)) pl.EndTangent = null;
document.UndoHistory.PopEnable();//restore the undo history to previous state

Send comments on this topic.