Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SOLIDWORKS VISUAL BASIC

Status
Not open for further replies.

Tug

Mechanical
Nov 29, 2002
12
0
0
US
I am using Solidworks and have created a macro that populates text in a drawing sheet. It puts information in the custom properties that gets read by the text on the drawing sheet.

Is there a way to input text from your drawing sheet or custom properties into the text boxes or pulldown lists in the visual basic macro.

With no real programming experience I am struggling on this one, could anyone help. On another issue is there any code to center text on a drawing sheet
 
Replies continue below

Recommended for you

If I understand you correctly, you are filling the custom properties via FILE - PROPERTIES - CUSTOM in your part or assembly.

Then linking a note in your drawing to these custom properties.

And your question is how do I enter the the info/text from the drawing?



Remember...
"If you don't use your head,
your going to have to use your feet."
 
And by centering text, do you mean centered within the note or the note centered within a drawing view or the note cetered on the drawing sheet?



Remember...
"If you don't use your head,
your going to have to use your feet."
 
You are correct on both counts,

I want the macro to read the text on my drawing sheet so that you dont have to keep typing it out again if you have made a simple spelling mistake.

the text I want to be centered in the note, but I will also need to move the text so that is in a central position in the title block
 
I need a little more info....

"macro to read the text" ???
don't quite understand what you're trying to achieve

You may be past this but ...
Here's how I handle these things.

1) Title block material is stored with the parts/assemblies because once the drawing templates are set-up with their associated references, they are filled in automatically.

ie. In the model file, if you add a custom prop called "Revision", the drawing template will always fill a note block with the following text "PRPSHEET:{Revision}" automatically when the first view is inserted. Changing the custom prop data in the part/assy automatically updates the drawing when changed.

These note blocks shold be added to the sheet format via a right click on the drawing template - select EDIT SHEET FORMAT. Then add as many note blocks as you wish - then right click again and select EDIT SHEET and save as a new template.

2)Revision block material is kept in the drawing properties area. They are accessed via a "PRP:{Revision}" format

There are SW API calls for both.
If you can post your code, it can be modified to suit your needs.

I don't know if your macro is to create these notes because they are different for each drawing or if you follow my method the macro can create the same properties for every part/assy/drawing and modify them as neded.



Remember...
"If you don't use your head,
your going to have to use your feet."
 
Let me try again,

I know how to create the custom property using visual basic and I know how to get it to populate the drawing. What I want to know is can you reverse this process, can you get your custom property to show up in your text boxes when you run your macro, so that you do not have to type all the information again, and again, and again, catch my drift.
 
Dim sConfig As String
Dim retval As Boolean

sConfig = "" 'not config specific in this case

'set all custom defaults
Part.AddCustomInfo3 sConfig, "TITLETOP", swCustomInfoText, " "

Load frmCustom

'fill user interface data
frmCustom.txtTT = Part.CustomInfo2(sConfig, "TITLETOP")

Then you will need:

'update interface data
retval = Part.DeleteCustomInfo2(sConfig, "TITLEBOT")
retval = Part.AddCustomInfo3(sConfig, "TITLEBOT", swCustomInfoText, frmCustom.txtTB)



Remember...
"If you don't use your head,
your going to have to use your feet."
 
Forgot to add... modified for your use
frmCustom, txtTB, TITLETOP, TITLBOT are all from my macro/SW addin

btw... Do you know there is a SolidWorks forum here on Eng-Tips?



Remember...
"If you don't use your head,
your going to have to use your feet."
 
meintsi

Thanks for your help, looking at your code helped. What I did was modify it to suit my needs, as shown below.

Private Sub CommandButton3_Click()
Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc

UserForm1.TextBox16.Text = Part.CustomInfo("REVISION")
UserForm1.TextBox15.Text = Part.CustomInfo("TASK")
UserForm1.TextBox9.Text = Part.CustomInfo("DESCRIPTION 1")
UserForm1.TextBox24.Text = Part.CustomInfo("DESCRIPTION 2")
UserForm1.TextBox25.Text = Part.CustomInfo("DESCRIPTION 3")
UserForm1.TextBox26.Text = Part.CustomInfo("DESCRIPTION 4")
End Sub
 
Status
Not open for further replies.
Back
Top