AnsweredAssumed Answered

Moving dimensions via macro

Question asked by Bryson White on Oct 24, 2019
Latest reply on Oct 31, 2019 by Bryson White

I apologize for the length of this post. I’ve divided it into sections so you can skip straight to the question, then come back to the scenario if you need to. I’ve posted a related question in another thread—https://forum.solidworks.com/thread/236167—but this is definitely a different issue. I’m working at a company with sensitive information, so I won’t be able to show images, so I’ll try to be descriptive of what the scenario is and what’s going on.

 

Basic Question

How can I reference/select dimensions via API/macro in a specific sketch in a specific drawing view to be able to edit its arrangement (centered, etc.) or move it? I believe I’ve narrowed it down to the fact that it’s not the arranging/moving that’s the issue, but actually selecting the dimension that I’m trying to arrange. Here’s the backstory…

 

Model and Drawing Setup

The big picture goal is automating the drawing process of some standard assemblies that we have. For the assembly, imagine a box whose cover opens from the end. The end with this cover is considered the front of the box. There is also an assembly mounted inside the box. Typically, for a drawing, we pull in a right side view of the assembly as “Drawing View1,” then a projected front view is pulled off as “Drawing View2” and a projected rear view is pulled off as “Drawing View2.” “Drawing View1” has four standard dimensions of features that are shown on every drawing. “Drawing View2” has seven standard dimensions of features that are shown on every drawing. In the assembly, I have a display states set up: ENTIRE CASE has all used components shown, NO LID has the cover and all its hardware hidden so that the contents can be seen. On the drawing, in “Drawing View2” I can just select the NO LID display state to show that end of the box and be able to see the contents of the assembly inside. Some of the standard dimensions in that view are of the internal assembly. I realize that images would definitely help with visualizing this, but are you tracking so far?

 

Current State of Macro

That’s not the entire drawing, but that sets up the scenario for my question. That’s a description of how we do it manually, and the end drawing format can’t change. So far, I have all my views and dimensions being imported automatically via a macro. Unfortunately, I haven’t found a way to select a display state in a drawing view via Solidworks API, so I had to perform a workaround. The macro imports the views in these steps:

  • Import right side view as “Drawing View1” in the ENTIRE CASE display state at a specific location
  • Switch back to the assembly
  • Change the assembly to the NO LID display state
  • Switch back to the drawing
  • Import front view as “Drawing View2” at a specific location
  • Align “Drawing View2” horizontally by origin to “Drawing View1”
  • Switch back to the assembly
  • Change the assembly to the ENTIRE CASE display state
  • Switch back to the drawing and imports the remaining drawing views

The next step in the macro is to import annotations which include all the unsuppressed dimensions from the assembly that are marked to be imported. This includes the four dimensions in “Drawing View1” and the seven dimensions in “Drawing View2.” This actually brings me to the point in my process where my other question came up (https://forum.solidworks.com/thread/236167).

 

Question at Hand

And it finally brings me to the point of this post. I’m still working out the auto-arranging of my dimensions. Using the auto-dimension command in Solidworks doesn’t work, so I’m “manually” through the macro setting each dimension. Some are being moved to very specific location while others are just being centered along the dimension line. This is working great in “Drawing View1,” but not so much in “Drawing View2.” Through recording mini-macros and digging through the Solidworks API help, this is the code that I have for adjusting the first dimension location in “Drawing View1”:

swDimension = swModel.ActivateView("Drawing View1")
swDimension = swModel.Extension.SelectByID2("D1@03U 3-3 SKETCH@730301413000-1@Drawing View1", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0)
swDimension = swModel.EditDimensionProperties2(0, 0, 0, "", "", True, 9, 2, True, 12, 12, "", "", True, "", "", True)

 

For the sake of not making this post any more lengthy, we’ll assume that all the variables are defined and setup correctly. You’ll notice that I gave the sketches custom names so I can refer to them easily. The above lines of code work fine for all the dimensions in that view. What has not worked is using this same code for the dimensions in “Drawing View2.” Here are some things I’ve tried:

  • I have altered the above code by changing the view references to “Drawing View2” and the sketch reference to the custom-named sketch in that view.
  • I have Recorded a mini-macro editing the dimension in that view. I can record a macro editing the dimensions in View 1, reset the dimensions, and run the macro—it runs fine and changes the dims. If I record a macro editing the dimensions in View 2, reset the dimensions, and run the macro, nothing happens. Interestingly, when I record that second macro, I get something like this: boolstatus = Part.Extension.SelectByID2("D1@7300 AA STANDARD FRAME SKETCH@730301413000-1@Drawing View1", "DIMENSION", 0, 0, 0, False, 0, Nothing, 0). Even though I have verified that it is in fact “Drawing View2,” it still records as “Drawing View1.” Changing it to View2 in the recorded macro does nothing.
  • If I record a single macro of editing dimensions in View1 and View2, I can run the macro and it will change the dimensions in View1, but not the ones in View2.
  • I thought maybe it was getting stuck on View1 and not being able to move to View2, even though I’m using the command swModel.ActivateView("Drawing View2") to activate that view, so I tried deleting all the views except View2. I then tried recording a macro of editing a dimension in that view, but I couldn’t even edit the dimension. If I try to edit a dimension in that view, I get this warning: “This dimension cannot be edited. It is a deleted dimension shown as dangling.” I’m not seeing that warning as an issue necessarily, but I think it gives a clue as to what’s going on with not being able to select a dimension in that view via macro.

 

Back to the Basic Question

How can I reference/select dimensions in a specific sketch in a specific drawing view to be able to edit its arrangement or move it?

 

Thank you for being amazing and making it to the bottom of this post. Again, I apologize for its length, but I couldn’t really ask the question without laying down the scenario and stating what I had tried so far. Thank you in advance for any input you might have.

Outcomes