Set main view of assembly by .NET API ?

Set main view of assembly by .NET API ?

m.shemur
Contributor Contributor
920 Views
7 Replies
Message 1 of 8

Set main view of assembly by .NET API ?

m.shemur
Contributor
Contributor

Hello!

Could you help - Is there a possibility to change or to set main view of detail or assembly using .NET API ?

Thank you!

0 Likes
Accepted solutions (2)
921 Views
7 Replies
Replies (7)
Message 2 of 8

ChristianBlei
Advisor
Advisor

Hi,

 

as the main view of an assembly is dependent of the main part, a option is to use the .IsMainPart property of one of the assembly parts.

 

To set the view you code integrate the AS command "_AstM14SetAssemblyDetCS" in you code with AcDoc.SendStringToExecute or AcDoc.SendCommand or Ed.Command- all AutoCAD methods.

 

 

HTH,

Christian Blei

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
Message 3 of 8

m.shemur
Contributor
Contributor

Thanks for the answer!

But I have the following situation: we have a lot of angle profiles, and we need to have them on drawings always in the same position like on the picture. so we have to set main view every time for all profiles. I had a hope we can do this via API...

image.png

0 Likes
Message 4 of 8

Sebastian_Eiche
Mentor
Mentor

the problem is: the main view of the assembly is based on UCS. It's set by creating the the profile and afterwards it could be changed, but this also depend on the UCS. 
And I think not all of your profile are on the same rotation or orientation in the model. 
You could set your UCS and then select more then one profile, so you could maybe minimize the steps, but in the end there're will be a lot if you want to have all automatic.
Another way would be to use the necessary view manager to create everytime both views for angles?


Sebastian Eiche
Application Engineer @Mensch und Maschine acadGraph

EESignature

If this information was helpful, please use the Accept as Solution function, this make it easier for other users

Message 5 of 8

ChristianBlei
Advisor
Advisor
Accepted solution

Hi

 

I see no problem to set the UCS in relation to an angle's coordinate system.

In my opinion it is possible to automate this process if you can analyze which view is necessary.

 

HTH,

Christian Blei

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
Message 6 of 8

m.shemur
Contributor
Contributor

Hi

 

After reading your answers I also got this idea in my mind))

Thanks! I will try!

0 Likes
Message 7 of 8

ChristianBlei
Advisor
Advisor

Hi,

 

please let us know if you can make it to work.

 

Christian

Christian Blei
CBT Christian Blei Tools
christianblei.de
youtube.com/channel/UCxjA_NbeScQy9C0Z1xjwXpw
Message 8 of 8

m.shemur
Contributor
Contributor
Accepted solution

This code seems like works

My apologies, it's not very clean😀

So what it does - it gets angles, finds if they have any connected bolts from one or other side (by getting its Z vector), and sets UCS from the bolt side

I also tried to add possibility that bolt can be not perpendicular to the angle, so Z vector is not parallel to Y or Z vector of the angle

In the end I set CS to WCS 

 

using Autodesk.AdvanceSteel.DocumentManagement;
using Autodesk.AdvanceSteel.Modelling;
using AAG = Autodesk.AutoCAD.Geometry;
using System.Collections.Generic;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AdvanceSteel.CADLink.Database;
using Autodesk.AdvanceSteel.CADAccess;
using AAA = Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AdvanceSteel.Runtime;
using Autodesk.AutoCAD.Internal;

namespace SomeNameSpace
{
  public partial class SomeClass
    {
        [CommandMethodAttribute("TEST_GROUP", "SETUCS", "SETUCS", CommandFlags.Modal | CommandFlags.UsePickSet | CommandFlags.Redraw)]
        public void SETUCS()
        {
            UCSSetter uCSSetter = new UCSSetter();
        }
    }

    public class UCSSetter
    {
        ConterPointsAndVectorsInitializer pointsAndVectorsInitializer;
        Editor ed;
        ObjectsGetter anglesGetter;
        public UCSSetter()
        {
            using (DocumentAccess da = new DocumentAccess(null, false))
            {
                anglesGetter = new ObjectsGetter();
                ed = AAA.Application.DocumentManager.MdiActiveDocument.Editor;
                SetMainView();
                SetWCS(ed);
            }
        }


        public void SetMainView()
        {
            foreach (Beam beam in anglesGetter.ObjectsTypeOfBeam)
            {
                SetWCS(ed);
                pointsAndVectorsInitializer = new ConterPointsAndVectorsInitializer(beam);

                AAG.Point3d angleCenterPoint = new AAG.Point3d(pointsAndVectorsInitializer.CenterPoint.x,
                    pointsAndVectorsInitializer.CenterPoint.y,
                pointsAndVectorsInitializer.CenterPoint.z);
                AAG.Vector3d vxx = new AAG.Vector3d(pointsAndVectorsInitializer.VectorXBuild.x,
                    pointsAndVectorsInitializer.VectorXBuild.y, pointsAndVectorsInitializer.VectorXBuild.z);
                AAG.Vector3d vyy = new AAG.Vector3d(pointsAndVectorsInitializer.VectorYBuild.x,
                    pointsAndVectorsInitializer.VectorYBuild.y,
                    pointsAndVectorsInitializer.VectorYBuild.z);
AAG.CoordinateSystem3d angleCoordSystem = new AAG.CoordinateSystem3d(angleCenterPoint, vxx, vyy);
AAG.Matrix3d ecs = AAG.Matrix3d.AlignCoordinateSystem(AAG.Point3d.Origin, AAG.Vector3d.XAxis, AAG.Vector3d.YAxis, AAG.Vector3d.ZAxis, angleCoordSystem.Origin, angleCoordSystem.Xaxis, angleCoordSystem.Yaxis, angleCoordSystem.Zaxis); ed.CurrentUserCoordinateSystem = ecs; SelectObjects(new List<ObjectId>() { beam.GetObjectId() }); ed.Command(new object[] { "_AstM14SetAssemblyDetCS" }); } } private static void SetWCS(Editor ed) { AAG.CoordinateSystem3d WCS = new AAG.CoordinateSystem3d(AAG.Point3d.Origin, AAG.Vector3d.XAxis, AAG.Vector3d.YAxis); AAG.Matrix3d WCSMatr = AAG.Matrix3d.AlignCoordinateSystem (WCS.Origin, WCS.Xaxis, WCS.Yaxis, WCS.Zaxis, AAG.Point3d.Origin, AAG.Vector3d.XAxis, AAG.Vector3d.YAxis, AAG.Vector3d.ZAxis); ed.CurrentUserCoordinateSystem = WCSMatr; } void SelectObjects(List<ObjectId> objectsToSelect) { if (objectsToSelect.Count > 0) { List<Autodesk.AutoCAD.DatabaseServices.ObjectId> AutocadObjIDs = new List<Autodesk.AutoCAD.DatabaseServices.ObjectId>(); foreach (ObjectId item in objectsToSelect) { ObjectId itemObjectID = DatabaseManager.GetReprId(DatabaseManager.Open(item, FilerObject.eOpenMode.kNormal)); AutocadObjIDs.Add(new Autodesk.AutoCAD.DatabaseServices.ObjectId(itemObjectID.AsOldId())); } Utils.SelectObjects(AutocadObjIDs.ToArray()); } } } } public class ObjectsGetter { public List<ObjectId> selectedObjID { get; } = UserInteraction.SelectObjects(); public List<Beam> ObjectsTypeOfBeam { get; set; } public List<PlateBase> Plates { get; private set; } public ObjectsGetter() { ObjectsTypeOfBeam = new List<Beam>(); Plates = new List<PlateBase>(); GetObjectsFromSelection(); } void GetObjectsFromSelection() { FilerObject selectedObject; try { if (selectedObjID != null && selectedObjID.Count > 0) { for (int i = 0; i <= selectedObjID.Count - 1; i++) { try { i = GetNextNotNullIDobjectIndex(selectedObjID, i); } catch (IndexOutOfRangeException ex) { MessageBox.Show(ex.Message + " in object getter"); break; } selectedObject = DatabaseManager.Open(selectedObjID[i]); if (selectedObject.IsKindOf(FilerObject.eObjectType.kBeam)) { ObjectsTypeOfBeam.Add(selectedObject as Beam); } else if (selectedObject.IsKindOf(FilerObject.eObjectType.kPlateBase)) { Plates.Add(selectedObject as PlateBase); } else if (selectedObject.IsKindOf(FilerObject.eObjectType.kBoltPattern)) { BoltPattern bolt = selectedObject as BoltPattern; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } } public int GetNextNotNullIDobjectIndex(List<ObjectId> selectedObjID, int currentindex) { while ((DatabaseManager.Open(selectedObjID[currentindex]) == null) && (currentindex <= selectedObjID.Count - 1)) { currentindex++; if (currentindex > selectedObjID.Count - 1) { throw new IndexOutOfRangeException(); } } return currentindex; } } public class ConterPointsAndVectorsInitializer { public Point3d CenterPoint { get; private set; } private Beam angle; private Vector3d vectorXBuild; private Vector3d vectorYBuild; private Vector3d vectorZBuild; public Vector3d VectorXBuild { get { return vectorXBuild; } set { vectorXBuild = value; } } public Vector3d VectorYBuild { get { return vectorYBuild; } private set { vectorZBuild = value; } } public Vector3d VectorZBuild { get { return vectorZBuild; } set { vectorZBuild = value; } } public ConterPointsAndVectorsInitializer(Beam angle) { using (DocumentAccess da = new DocumentAccess(null, false)) { this.angle = angle; if (angle != null) { CenterPoint = GetCenterPoint(); InitializeVectors(); } } } private Point3d GetCenterPoint() { return angle.CenterPoint; } private void InitializeVectors() { angle.PhysCSStart.GetCoordSystem(out Point3d BeamStart, out Vector3d vectorX, out Vector3d vectorY, out Vector3d vectorZ); vectorXBuild = new Vector3d(vectorX); vectorYBuild = new Vector3d(-vectorY); vectorZBuild = new Vector3d(vectorZ); Vector3d boltZVector = GetBoltZVector(GetBolt()); if (boltZVector != null) { double angleRad = boltZVector.GetAngleTo(vectorZBuild); if (Math.Abs(angleRad) > Math.PI / 4 && Math.Abs(angleRad) < 3 * Math.PI / 4) { RotateBuildVectors(ref vectorXBuild, ref vectorYBuild, ref vectorZBuild, vectorX, vectorY, vectorZ); } } } private BoltPattern GetBolt() { int number = angle.NumberOfDrivenConObj; for (int i = 0; i < number; i++) { PassiveConstructionObject bolts = angle.GetDrivenConObj(i); ConnectionConstructionObject boltsconn = bolts as ConnectionConstructionObject; Autodesk.AdvanceSteel.Connection.Connection con = boltsconn.GetConnection(); if (con.getMeans(0).IsKindOf(FilerObject.eObjectType.kBoltPattern)) { BoltPattern bolt = con.getMeans(0) as BoltPattern; return bolt; } } return null; } private Vector3d GetBoltZVector(BoltPattern bolt) { if (bolt != null) { bolt.CS.GetCoordSystem(out Point3d BeamStart, out Vector3d vectorX, out Vector3d vectorY, out Vector3d vectorZ); return vectorZ; } return null; } private void RotateBuildVectors(ref Vector3d vectorXBuild, ref Vector3d vectorYBuild, ref Vector3d vectorZBuild, Vector3d vectorX, Vector3d vectorY, Vector3d vectorZ) { vectorXBuild = -vectorX; vectorYBuild = -vectorZ; vectorZBuild = vectorY; } }

 

 

0 Likes