Dear @Anonymous. I have this code that creates a "DetailCurve" and assigns a line style (Image 1) based on a "DataGridView" (Image 2).
Steps:
1. Checks the diameter of the bar and looks for it in the first column of the DataGridView, gets the match, and returns the "Category" found in the second column.
2. Draw the "DetailCurve" based on a view and an "IList <Curve>".
3. With that "Category" create the "GraphicsStyle" with a "GraphicsStyleType.Projection".
4. Finally, assign that "GraphicsStyle" to the "DetailCurve" created previously.
///<summary> Cambia el estilo de la línea en función del DataGridView </summary>
public static List<Element> DibujarArmaduraSegunDatagridview(System.Windows.Forms.DataGridView dgv, Document doc, Rebar barra, View vista)
{
// Obtiene el diámetro de la barra
RebarBarType barraDiametro = doc.GetElement(barra.GetTypeId()) as RebarBarType;
// Crea la lista de las lineas a devolver
List<Element> listaLineas = new List<Element>();
// Crea la lista de los estilos de lineas del proyecto
List<Category> estilos = Tools.ObtenerEstilosDeLinea(doc);
// Variable necesarias
Category cat = null;
// Ajustar las curvas si se superponen
bool superposicion = false;
// Omitir ganchos
bool ganchos = false;
// Omitir los diámetros de doblez
bool radioDeGiro = false;
// Define si es Multi-Planar o no
MultiplanarOption multiplePlano = MultiplanarOption.IncludeOnlyPlanarCurves;
// Selecciona cual barra del conjunto dibuja
int posicion = 0; //barra.NumberOfBarPositions - 1;
// Obtiene una lista con curvas de la linea central de la barra
IList<Curve> listaCurva = barra.GetCenterlineCurves(superposicion, ganchos, radioDeGiro, multiplePlano, posicion);
try
{
// Recorre todas las curvas de la lista
foreach (Curve curva in listaCurva)
{
// Recorre el DataGridView
for (int i = 0; i < dgv.Rows.Count; i++)
{
// Compara el nombre de la celda con el diámetro de la barra
if (dgv.Rows[i].Cells[0].Value.ToString() == barraDiametro.Name)
{
// Crea una serie de curvas con lineas de detalle
DetailCurve curvaDetalle = doc.Create.NewDetailCurve(vista, curva);
// Obtiene la categoría del estilo de línea
cat = estilos.FirstOrDefault(x => x.Name == dgv.Rows[i].Cells[1].Value.ToString());
// Crea el estilo de gráfico en función del estilo de línea
GraphicsStyle gra = cat.GetGraphicsStyle(GraphicsStyleType.Projection);
// Asigna el estilo a la línea
curvaDetalle.LineStyle = gra;
// Agrega la linea a la lista de lineas
listaLineas.Add(curvaDetalle);
}
}
}
}
catch (Exception) { }
return listaLineas;
}
I hope it helps you, greetings.