У меня есть этот код на C#, работающий на .NET 4.8 в Visual Studio 2022. Кто-нибудь знает, как перейти от чередования двух цветов на объекте Solid3d к рисованию чередования двух цветов на каждой грани в объекте Solid3d?Более конкретно: при выборе 2 цветов в окне рисования Autocad (1-255) цвет1 будет применяться к четным граням, цвет2 будет применяться к нечетным граням. Я хочу изменить его так, чтобы оба цвета применялись поочередно на каждой грани объекта Solid3d.
Еще одна вещь, которую я сначала попробую использовать метод Solid3d.SetSubentityMaterial (Solid3d.SetSubentityColor применяет один цвет), но не удалось, кто-нибудь знает способ получше?
Вот мой код:
private void ApplyColorsTo3DObject()
{
// Get the active document and its database
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Check if both colors have been chosen, if not, prompt the user
if (_color1 == null || _color2 == null)
{
ed.WriteMessage("\nPlease choose 2 colors.");
return;
}
// Lock the document to prevent other operations while applying the colors
using (var lck = doc.LockDocument())
{
// Prompt the user to select a 3D object
PromptEntityOptions peo = new PromptEntityOptions("\nSelect 3D object:");
peo.SetRejectMessage("\nNot a Solid3d object.");
peo.AddAllowedClass(typeof(Solid3d), true); // Only allow Solid3d objects
var per = ed.GetEntity(peo);
// If the user did not select an object, exit the function
if (per.Status != PromptStatus.OK)
{
ed.WriteMessage("\nObject not found.");
return;
}
// Start a transaction to modify the 3D object
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Get the Solid3d object from the ObjectId
Solid3d solid3d = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d;
if (solid3d == null)
{
// If the selected object is not a valid Solid3d, show an error
ed.WriteMessage("\nSelected object is not a valid Solid3d.");
return;
}
// Create a FullSubentityPath to access the BREP (boundary representation)
var fullSubentityPath = new FullSubentityPath(new[] { per.ObjectId }, new SubentityId(SubentityType.Null, IntPtr.Zero));
using (var brep = new Brep(fullSubentityPath))
{
int faceIndex = 0;
var faces = brep.Faces.ToArray(); // Get all the faces of the 3D object
// Loop through each face and apply alternating colors
foreach (var face in faces)
{
try
{
var subEntityId = face.SubentityPath.SubentId;
var colorToApply = (faceIndex % 2 == 0) ? _color1 : _color2; // Apply color1 to even faces, color2 to odd faces
solid3d.SetSubentityColor(subEntityId, colorToApply); // Set the color of the face
faceIndex++; // Move to the next face
}
catch (System.Exception ex)
{
// Handle any exceptions and display an error message
ed.WriteMessage($"\nERROR: {ex.Message}");
}
}
// Commit the transaction to apply the changes
tr.Commit();
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... rx-autocad
Нужна помощь по изменению кода в ObjectArx Autocad. ⇐ C#
Место общения программистов C#
-
Anonymous
1733723847
Anonymous
У меня есть этот код на C#, работающий на .NET 4.8 в Visual Studio 2022. Кто-нибудь знает, как перейти от чередования двух цветов на объекте Solid3d к рисованию чередования двух цветов на каждой грани в объекте Solid3d?Более конкретно: при выборе 2 цветов в окне рисования Autocad (1-255) цвет1 будет применяться к четным граням, цвет2 будет применяться к нечетным граням. Я хочу изменить его так, чтобы оба цвета применялись поочередно на каждой грани объекта Solid3d.
Еще одна вещь, которую я сначала попробую использовать метод Solid3d.SetSubentityMaterial (Solid3d.SetSubentityColor применяет один цвет), но не удалось, кто-нибудь знает способ получше?
Вот мой код:
private void ApplyColorsTo3DObject()
{
// Get the active document and its database
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
// Check if both colors have been chosen, if not, prompt the user
if (_color1 == null || _color2 == null)
{
ed.WriteMessage("\nPlease choose 2 colors.");
return;
}
// Lock the document to prevent other operations while applying the colors
using (var lck = doc.LockDocument())
{
// Prompt the user to select a 3D object
PromptEntityOptions peo = new PromptEntityOptions("\nSelect 3D object:");
peo.SetRejectMessage("\nNot a Solid3d object.");
peo.AddAllowedClass(typeof(Solid3d), true); // Only allow Solid3d objects
var per = ed.GetEntity(peo);
// If the user did not select an object, exit the function
if (per.Status != PromptStatus.OK)
{
ed.WriteMessage("\nObject not found.");
return;
}
// Start a transaction to modify the 3D object
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// Get the Solid3d object from the ObjectId
Solid3d solid3d = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Solid3d;
if (solid3d == null)
{
// If the selected object is not a valid Solid3d, show an error
ed.WriteMessage("\nSelected object is not a valid Solid3d.");
return;
}
// Create a FullSubentityPath to access the BREP (boundary representation)
var fullSubentityPath = new FullSubentityPath(new[] { per.ObjectId }, new SubentityId(SubentityType.Null, IntPtr.Zero));
using (var brep = new Brep(fullSubentityPath))
{
int faceIndex = 0;
var faces = brep.Faces.ToArray(); // Get all the faces of the 3D object
// Loop through each face and apply alternating colors
foreach (var face in faces)
{
try
{
var subEntityId = face.SubentityPath.SubentId;
var colorToApply = (faceIndex % 2 == 0) ? _color1 : _color2; // Apply color1 to even faces, color2 to odd faces
solid3d.SetSubentityColor(subEntityId, colorToApply); // Set the color of the face
faceIndex++; // Move to the next face
}
catch (System.Exception ex)
{
// Handle any exceptions and display an error message
ed.WriteMessage($"\nERROR: {ex.Message}");
}
}
// Commit the transaction to apply the changes
tr.Commit();
}
}
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79263917/need-helf-about-change-the-code-in-objectarx-autocad[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия