Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
i stuck at this problem Argument 2: cannot convert from 'void' to 'Autodesk.AutoCAD.Colors.Color'
does anyone know how to fix this or give me an advise how to fix this
im using C#.net framework 4.8
private void ApplyColorsTo3DObject()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
if (_color1 == null || _color2 == null)
{
ed.WriteMessage("\nPlease choose two colors.");
return;
}
using (var docLock = doc.LockDocument())
{
PromptEntityOptions peo = new PromptEntityOptions("\nSelect a 3D solid:");
peo.SetRejectMessage("\nOnly 3D solids are allowed.");
peo.AddAllowedClass(typeof(Solid3d), true);
var per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK)
{
ed.WriteMessage("\nNo valid 3D solid selected.");
return;
}
using (Transaction tr = db.TransactionManager.StartTransaction())
{
Solid3d solid3d = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d;
if (solid3d == null)
{
ed.WriteMessage("\nSelected object is not a valid Solid3d.");
return;
}
try
{
// Tạo FullSubentityPath để truy cập BREP
var fullSubentityPath = new FullSubentityPath(new[] { per.ObjectId }, new SubentityId(SubentityType.Null, IntPtr.Zero));
using (var brep = new Brep(fullSubentityPath))
{
int faceIndex = 0;
foreach (Autodesk.AutoCAD.BoundaryRepresentation.Face face in brep.Faces)
{
try
{
// Lấy SubentityId của mặt
var subEntityId = face.SubentityPath.SubentId;
// Chọn màu xen kẽ dựa trên chỉ số mặt
var colorToApply = (faceIndex % 2 == 0) ? _color1 : _color2;
solid3d.SetSubentityColor(subEntityId, ApplyColorToFace(solid3d, face, colorToApply));
faceIndex++;
}
catch (System.Exception ex)
{
ed.WriteMessage($"\nError applying color to face: {ex.Message}");
}
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage($"\nError processing solid: {ex.Message}");
}
tr.Commit();
}
}
}
private void ApplyColorToFace(Solid3d solid, Autodesk.AutoCAD.BoundaryRepresentation.Face face, Autodesk.AutoCAD.Colors.Color color)
{
try
{
var subentityId = face.SubentityPath.SubentId;
solid.SetSubentityColor(subentityId, color);
}
catch (System.Exception ex)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage($"\nError applying color: {ex.Message}");
}
}
Solved! Go to Solution.