Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObjectARX Problem #165

Open
HarshaVardhanYellanki opened this issue Dec 1, 2023 · 2 comments
Open

ObjectARX Problem #165

HarshaVardhanYellanki opened this issue Dec 1, 2023 · 2 comments

Comments

@HarshaVardhanYellanki
Copy link

Could you help me out with .net objectArx ??

I would like to create a layout with 6 views in it(Top, Front, Left, Right, Bottom , Back ). The views should fit in the viewports accurately and the visual style be hidden. The views should be black in color so that i can view them when exported. Finally export the pdf.

ObjectARX code:

private static void StyleViewport(Autodesk.AutoCAD.DatabaseServices.Viewport viewport)
{
using (Database db = HostApplicationServices.WorkingDatabase)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// "Hidden" is the name of the visual style you want
viewport.VisualStyleId = GetVisualStyleId(db, "Hidden");

// Set other properties if needed
viewport.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 0, 0);

tr.Commit();
}
}
}

[CommandMethod("InsertViewsToLayout")]
public static void InsertViewsToLayout()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;

using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;

// Switch to the previous Paper space layout
Application.SetSystemVariable("TILEMODE", 0);
acDoc.Editor.SwitchToPaperSpace();

// Get the current layout
LayoutManager acLayoutMgr = LayoutManager.Current;
Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite) as Layout;

Point3d[] viewPositions = {
new Point3d(2.5, 5.5, 0),
new Point3d(2.5, 2.5, 0),
new Point3d(5.5, 5.5, 0),
new Point3d(5.5, 2.5, 0),
new Point3d(8.5, 5.5, 0),
new Point3d(8.5, 2.5, 0)
};

Vector3d[] viewDirections = {
new Vector3d(0, 0, -1),
new Vector3d(0, 0, 1),
new Vector3d(-1, 0, 0),
new Vector3d(1, 0, 0),
new Vector3d(0, -1, 0),
new Vector3d(0, 1, 0)
};

for (int i = 0; i < viewPositions.Length; i++)
{
using (Autodesk.AutoCAD.DatabaseServices.Viewport acVport = new Autodesk.AutoCAD.DatabaseServices.Viewport())
{
acVport.CenterPoint = viewPositions[i];
acVport.Width = 2.5;
acVport.Height = 2.5;

// Add the new viewport to the layout's block table record
acBlkTblRec.AppendEntity(acVport);
acTrans.AddNewlyCreatedDBObject(acVport, true);

// Set the view direction
acVport.ViewDirection = viewDirections[i];

// Set the visual style
StyleViewport(acVport);

// Enable the viewport
acVport.On = true;
}
}

acTrans.Commit();
acDoc.Editor.Regen();
}
}

Here's my code:
Error is :
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'GetVisualStyleId' does not exist in the current context AutoCad C:\Users\source\repos\AutoCad\AutoCad\Commands.cs 268 Active

i am trying a lot but unable to figure out the solution.
Please resolve my issue.

You can also modify approach of viewports, You can insert views using "Base->Model Space" that way...

@tarikjabiri
Copy link
Member

Hi,

I am sorry, I never used the ObjectARX SDK, so I can't help you.

Regads.

@HarshaVardhanYellanki
Copy link
Author

Its okay

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants