How do I move a dimension in a PEM using a macro?

Hello

I want to move dimensions in my drawing. Being self-taught on SolidWorks macros, I use macro recording to guide me, but here I stumble. Indeed, following the movement of a dimension, the recorded macro returns me:

boolstatus = Part.Extension.SelectByID2("Drawing D1@Vue 1", "DIMENSION", 3.20196294133094E-02, 0.121152137881271, 0, False, 0, Nothing, 0)'Start dimension position

boolstatus = Part.Extension.SelectByID2("Drawing D1@Vue 1", "DIMENSION", 8.08807508164743E-02, 0.118580499912683, 0, False, 0, Nothing, 0)'Position of the dimension when moved

I therefore conclude that the numbers in bold define the position of the dimension. However, when I run these command lines, even if the number changes, the dimension doesn't move at all. I must be taking it badly. Could you help me?

Thank you in advance.

Hello

In fact the instruction used is SELECT: so it's only used to select the dimension!

To move it, you have to use SETPOSITION:
http://help.solidworks.com/2011/English/api/sldworksapi/SolidWorks.Interop.sldworks~SolidWorks.Interop.sldworks.IAnnotation~SetPosition.html

See the examples here:

https://forum.solidworks.com/thread/49057

http://help.solidworks.com/2011/English/api/sldworksapi/Insert_a_Note_Example_VB.htm

 

Hello

Just out of curiosity: what's the point of moving a dimension via a macro? My field mouse does this very well!

 

3 Likes

+ 1000 to @ TicTic

I don't see the use of a macro to move a dimension in a drawing on SW

Is it out of curiosity what to do???

the dimension to be moved is a dimension created in the mép or a dimension that comes from the 3 D

@+

 

Hello

Thank you ".PL" for your answer, I'm looking for how to use "SETPOSITION". I admit to having a bit of trouble but I'm only at the beginning of my research.

To answer the question about the usefulness of moving the position of a dimension in a MEP, it is in fact a question of always positioning dimensions in the same place, which changes position according to the dimensions of the part while keeping the same name. More precisely: I have a part with several active or non-active functions and dimensions that also change. Everything is configured from an Excel file that runs a macro that places the right dimensions of each dimension. I don't use room families. Once the import of these dimensions and functions active or not, the part is rebuilt and imported into my MEP. Dimensions are also imported but appear randomly (even with the "as on sketch" option). So I decided to fix their position on the plan. Because the average user just needs to configure the Excel file and have a printable plan without having to reposition dimensions.

Thank you all

I don't know if it can help you, but in the drawing options, I advise you to uncheck:

Reduce spacing when removing or changing dimensions (adding or changing tolerances, text, etc.)

 

http://help.solidworks.com/2012/french/SolidWorks/sldworks/HIDD_OPTIONS_DRAWINGS_GENERAL.htm

 

And why not just take

the automatic quotation option of S W 

if it's substantially identical parts

The grades should in theory be in the same place  unless the rib refs are added

Thank you for your suggestions, however I have already tested many of the software possibilities on the import or formatting of dimensions and none of them allow a standardized result that can be used without retouching, in fact the automatic dimensions overlap and do not appear in compliance with the rules of industrial design. This just makes it possible to rough up the display but not to make it standardized. In addition, I also have angular dimensions which are the worst to import automatically, because depending on the angle, the dimension can be at the other end of the plane^^

I'm still trying to use "SetPosition" but I'm struggling with declarations. If anyone has a simple example, which would take for example the selection of a dimension with the name "N" and a position "X,Y" to make it go to the position "X',Y'" I am interested ^^

Dim swApp As Object

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set Part = swApp.ActiveDoc

boolstatus = Part.ActivateView("Layout View1")

boolstatus = Part.Extension.SelectByID2("N", "DIMENSION", X, Y, 0, True, 0, Nothing, 0)

….

boolstatus = ............. SetPosition(X', Y', 0)

......

End Sub