Hi I wonder if someone can help me create a macro.
My problem is this would make a window as the image, where I fill up the fields with the measures x and y when you press the OK button is the size as the fields are completed.
You can use code from this macro to make the one you need: Rectangular Block (In Inches)
But that changes needed to the sketch that already exists and does not create a new
is it possible?
I change Sketch1 and for dimensions line D1@Sketch1 and D2@Sketch1,
The macro would have to modify these values.
Yes. Let me make the macro and send your way.
Deepak Gupta, I wonder if it was possible to create the macro? thanks
Thank you, worked perfectly.
I also used and edit your macro, thanks for that!
What I wonder, is it possible to autofill the userform fields with the current dimensions?
I'd also like the screen to disappear and auto rebuild the model. Is it hard to do?
Willem Van Opstal wrote: What I wonder, is it possible to autofill the userform fields with the current dimensions?
Willem Van Opstal wrote:
Yes it can be done. What you ant to do with those dimensions OR user form further?
I'm doing a small project on structural analysis. What I have is a model with 10 main dimensions which should be easily editable (I'll put the macro in a custom toolbar along with some evaluation tools). The entire model is already dependent on those few dimensions.
This is for non-experienced SW users, so a small UI is appreciated (check image). The rebuilding and exiting the inputform is already working!
What I would like is putting the 'current' dimensions in the textbox as a default.
You can use something like this (based on my above macro) to populate dimensions
Private Sub UserForm_Initialize()txtHeight.Text = Part.Parameter("D1@Sketch1").SystemValuetxtWidth.Text = Part.Parameter("D2@Sketch1").SystemValueEnd Sub
Private Sub UserForm_Initialize()
txtHeight.Text = Part.Parameter("D1@Sketch1").SystemValue
txtWidth.Text = Part.Parameter("D2@Sketch1").SystemValue
Please note that linear dimensions are returned in meters while angles are in radians. So please multiple or divide by the correct factor to get the values in required units.
Hi Deepak, thanks for the help!
I implemented this into the code, but receiving an error message. Something like the form isn't declared;
"Runtime error 91, Object variable or With block variable not set"
Debugging points at the "Load Form1" line in rec1.
Can you post the updated macro and I can debug that.
Thought I had already done that.. I'm sorry, here's it again: Thanks!
Sorry I wanted to say to attach a file used along with the macro.
You must have the file open which has all the values before running the macro and it should work fine.
This one should work, the entire model is too big.
Add these line in the UserForm_Initialize sub as the form is failing to get the required value. And it won't do that until it is connected to the active model.
Set swApp = Application.SldWorksSet Part = swApp.ActiveDoc
Set swApp = Application.SldWorks
Set Part = swApp.ActiveDoc
Please let us know how to take forward to solid works for this macro?
The macro and changes have been suggested already. What else you want to know?
Hi Deepak Gupta,is it possible to change the dimension of the part without changing the hole position of the part ? thank you,
Yes Lee. There are two ways:
I have recorded a macro to edit four dimensions, but I want to create a userform and also dimension need to provide in inches for that, can you please help me on this, my recorded code as below,
Dim swApp As slworks.SldWorksDim Part As ModelDoc2Dim boolstatus As BooleanDim longstatus As Long, longwarnings As LongSub main()Set swApp = Application.SldWorksSet Part = swApp.ActiveDocboolstatus = Part.Extension.SelectByID2("Sketch10", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)Part.EditSketchPart.ClearSelection2 Trueboolstatus = Part.Extension.SelectByID2("D1@Sketch10@105208241.SLDASM", "DIMENSION", 0.961517176650177, 2.98667139945203E-02, 0, False, 0, Nothing, 0)Dim myDimension As Object
'Need create a userform and mentioned the below value as ASet myDimension = Part.Parameter("D1@Sketch10")myDimension.SystemValue = 0.1517777Part.ClearSelection2 TruePart.SketchManager.InsertSketch Trueboolstatus = Part.Extension.SelectByID2("Sketch8", "SKETCH", 0, 0, 0, False, 0, Nothing, 0)Part.EditSketchPart.ClearSelection2 True'Need create a userform and mentioned the below value as Bboolstatus = Part.Extension.SelectByID2("D18@Sketch8@105208241.SLDASM", "DIMENSION", 1.33001211332331, -7.39688449086132E-03, 0, False, 0, Nothing, 0)Set myDimension = Part.Parameter("D18@Sketch8")myDimension.SystemValue = 0.1080135'Need create a userform and mentioned the below value as C
boolstatus = Part.Extension.SelectByID2("D20@Sketch8@105208241.SLDASM", "DIMENSION", 1.43308365733179, -0.012376186133783, 0, False, 0, Nothing, 0)Set myDimension = Part.Parameter("D20@Sketch8")myDimension.SystemValue = 0.1144905'Need create a userform and mentioned the below value as Dboolstatus = Part.Extension.SelectByID2("D19@Sketch8@105208241.SLDASM", "DIMENSION", 1.64370811682738, -1.43679067909516E-02, 0, False, 0, Nothing, 0)Set myDimension = Part.Parameter("D19@Sketch8")myDimension.SystemValue = 0.1063244boolstatus = Part.Extension.SelectByID2("", "FACE", 1.60237991319113, -9.88653531232163E-03, 7.29935066942176E-02, False, 0, Nothing, 0)Part.SketchManager.InsertSketch TruePart.ShowNamedView2 "*Isometric", 7Part.ViewZoomtofit2Part.ClearSelection2 TruePart.ViewZoomtofit2End Sub
'Also need to mention the values in inches
Rather than resurrecting a thread that is already answered, I recommend starting your own thread. It would help if you attach a part with the before and after that you're looking for along with an attempt at coding more than recording a macro. The recorded macro doesn't actually tell us what you're trying to do and the values recorded aren't usually helpful in the long run.
Yes Alex, I am agreeing with your statement, but for time being I have planned to record and modify. I need to submit the automation for my final year project by end of this week. I am helpless now. Can you please help me on this.
Retrieving data ...