-
Re: Open a part invisibly while drawing is already open
Alex Burnett Aug 23, 2017 9:50 AM (in response to Nadav Gover)-
Re: Open a part invisibly while drawing is already open
Nadav Gover Aug 23, 2017 10:04 AM (in response to Alex Burnett)I saw this and thought it would be the answer, but with no luck
-
Re: Open a part invisibly while drawing is already open
Alex Burnett Aug 23, 2017 10:17 AM (in response to Nadav Gover)If you're just looking for a way to get the referenced model that the drawing uses then the following code can be translated from c# to VBA and work. The model.AsDrawing() line is part of a plugin that I'm using but if you get the drawing object as a DrawingDoc object then this does the same thing. The rest should translate fairly well.
once you have the refModelDoc2 object, then you can sort through the contents of the file without actually activating the document. I used it here to obtain the mass properties of the referenced file to determine if the custom property for the weight in the same file is accurate and in the correct units.
var swDraw = model.AsDrawing(); var swSheet = (Sheet)swDraw.GetCurrentSheet(); var sheetView = (SolidWorks.Interop.sldworks.View)swDraw.GetFirstView(); // Gets current drawing sheet as "view" var modelView = (SolidWorks.Interop.sldworks.View)sheetView?.GetNextView(); // Gets first view on sheet if (swSheet.CustomPropertyView != "Default") // Checks if the referenced view that the drawing uses to get custom properties is default { while (modelView.Name != swSheet.CustomPropertyView) { modelView = (View)modelView.GetNextView(); // sets modelView to the view that is referenced for custom properties } } var refModelDoc2 = modelView?.ReferencedDocument; // Gets referenced ModelDoc2 item from the view on the sheet
-
Re: Open a part invisibly while drawing is already open
Nadav Gover Aug 28, 2017 1:14 AM (in response to Alex Burnett)Thanks Alex it is also what i tried (I'm also using c#)
but the problem is that I can't get the feature manager and extension of the part to work.
the feature manager is the drawing's manager.
Do you have any idea?
Thanks
-
Re: Open a part invisibly while drawing is already open
Alex Burnett Aug 28, 2017 8:51 AM (in response to Nadav Gover)I tested out using the refModelDoc2 object from my code to iterate through the feature tree and it worked with this code snippet I found online. I'm not sure why yours isn't working. I'm not using the FeatureManager like you are here but I made sure that I could set it to something and it was not null. It contained all of the variables I would expect it to have.
Code:
for(int x=0; x< refModelDoc2.GetFeatureCount(); x++) { Feature swFeat = (Feature)refModelDoc2.FeatureByPositionReverse(x); if(swFeat != null) { Trace.WriteLine("Feature: " + swFeat.Name + " [" + swFeat.GetTypeName() + "]"); } }
Output:
Feature: M1.2x0.25 Tapped Hole1 [HoleWzd] Feature: Point1 [RefPoint] Feature: Coordinate System1 [CoordSys] Feature: Axis1 [RefAxis] Feature: Cut-Extrude1 [Cut] Feature: Sketch2 [ProfileFeature] Feature: Boss-Extrude1 [Extrusion] Feature: Sketch1 [ProfileFeature] Feature: Tables [ConfigTableFolder] Feature: MateReferences___EndTag___ [FtrFolder] Feature: Default-<1> [PosGroupFolder] Feature: MateReferences [MateReferenceGroupFolder] Feature: Origin [OriginProfileFeature] Feature: Right Plane [RefPlane] Feature: Top Plane [RefPlane] Feature: Front Plane [RefPlane] Feature: 1060-O [MaterialFolder] Feature: Equations [EqnFolder] Feature: Lights, Cameras and Scene [EnvFolder] Feature: Solid Bodies [SolidBodyFolder] Feature: Surface Bodies [SurfaceBodyFolder] Feature: Annotations [DetailCabinet] Feature: Design Binder [DocsFolder] Feature: Sensors [SensorFolder] Feature: Selection Sets [SelectionSetFolder] Feature: History [HistoryFolder] Feature: Favorites [FavoriteFolder] Feature: Comments [CommentsFolder]
-
Re: Open a part invisibly while drawing is already open
Josh Brady Aug 28, 2017 9:09 AM (in response to Nadav Gover)Nadav,
Every document always has its own feature manager and its own extension. You have to get the feature manager or extension from the ModelDoc2 you're interested in. You have to do something like:
dim myDwg as sldworks.drawingdoc
dim myDoc as sldworks.modeldoc2
dim myView as sldworks.View
dim myMgr as sldworks.featuremanager
dim myExt as sldworks.modeldocextension
....
set myDwg = swapp.activedoc
set myView = myDwg.activeview
set myDoc = myView.ReferencedDocument
set myMgr = myDoc.FeatureManager
set myExt = myDoc.Extension
-
-
-
-
-
Re: Open a part invisibly while drawing is already open
Deepak Gupta Aug 23, 2017 9:52 AM (in response to Nadav Gover)The model always open invisibly when you open a drawing. So what exactly you looking to do with the model?
-
Re: Open a part invisibly while drawing is already open
Dan Pihlaja Aug 23, 2017 9:54 AM (in response to Deepak Gupta)Deepak Gupta wrote:
The model always open invisibly when you open a drawing. So what exactly you looking to do with the model?
Unless you are opening a detached drawing... but that is probably not what he is doing. Never mind....nothing to see here.
-
Re: Open a part invisibly while drawing is already open
Nadav Gover Aug 23, 2017 10:03 AM (in response to Deepak Gupta)I want to activate it (activatedoc2) and traverse it's features
-
Re: Open a part invisibly while drawing is already open
Deepak Gupta Aug 23, 2017 11:24 AM (in response to Nadav Gover)If you want to activate it then try using OpenDoc7
-
-
-
Re: Open a part invisibly while drawing is already open
John Alexander Aug 23, 2017 9:59 AM (in response to Nadav Gover)When a drawing is open that contains a view of a part/assembly, I believe the assembly/part documents are already loaded in memory. You can access them through the drawing's view object in which they are depicted.
2012 SOLIDWORKS API Help - ReferencedDocument Property (IView)
There might be a better approach that doesn't require views on the drawing but this has been my method for most drawing macros that I've worked on.
-
Re: Open a part invisibly while drawing is already open
Nadav Gover Aug 28, 2017 10:57 AM (in response to Nadav Gover)Thanks guys it's solved thanks to you.
The answer was a combination of Alex's and Josh's answers.
I was able to get rid of "ActivateDoc2" which opened the part visually.
I now use the FaetureManager from the ReferencedDocument.
Thank you yessss