Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

API - get dimension value - HOW ???

1,219 views
Skip to first unread message

Poul B.

unread,
Oct 10, 2001, 9:09:24 AM10/10/01
to
Hi all.

I'm writing a small macro that's able to set prefix and suffix for a
selected dimension.

I just need to figure out how to get a returnvalue that returns the
dimension value, since I need this value to determine which suffix that
should be used.

But I really can't find any usefull information (or I just don't understand
it at all *L*) in the API help.

Best regards

Poul B.


Michael Penther Skytte

unread,
Oct 10, 2001, 12:51:14 PM10/10/01
to
Hi Poul

____________
Try

Dimension::GetValue2(configName As String) As Double
Dimension::GetSystemValue2(configName As String) As Double
_________

Here a little example where the name of the dimension is known
Option Explicit

Const swSelDIMENSIONS As Long = 14

Const Config1Name As String = "Default"
Const Config2Name As String = "First Instance"
Const DimName As String = "SL@Base-Extrude-Thin@getvalue_part.SLDPRT"

Sub main()
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc
Dim swPart As SldWorks.PartDoc
Dim swSelMgr As SldWorks.SelectionMgr
Dim swDim As SldWorks.Dimension
Dim swDispDim As SldWorks.DisplayDimension
Dim DimVal As Double
Dim DimSysVal As Double
Dim bRet As Boolean
Dim nSelType As Long

Set swApp = CreateObject("SldWorks.Application")
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager

bRet = swModel.SelectByID(DimName, "DIMENSION", 0#, 0#, 0#)
nSelType = swSelMgr.GetSelectedObjectType(1)

Set swDispDim = swSelMgr.GetSelectedObject3(1)
Set swDim = swDispDim.GetDimension

DimVal = swDim.GetValue2(Config1Name)
DimSysVal = swDim.GetSystemValue2(Config1Name)
Debug.Print "Value (" + Config1Name + ") = " + Str(DimVal) + " mm"
Debug.Print "SysValue(" + Config1Name + ") = " + Str(DimSysVal * 1000) +
" mm"

DimVal = swDim.GetValue2(Config2Name)
DimSysVal = swDim.GetSystemValue2(Config2Name)
Debug.Print "Value (" + Config2Name + ") = " + Str(DimVal) + " mm"
Debug.Print "SysValue(" + Config2Name + ") = " + Str(DimSysVal * 1000) +
" mm"
End Sub
'----------------------------------------------------------

Best regards
Michael


"Poul B." <p...@12move.dk> wrote in message
news:%SXw7.296$TU1....@news.get2net.dk...

Dan Andrews

unread,
Oct 10, 2001, 1:49:33 PM10/10/01
to
"Poul B." <p...@12move.dk> wrote in message news:<%SXw7.296$TU1....@news.get2net.dk>...

Let's debug something from the help file.

{---------------------------}

' This code assumes you have a feature selected. It will then traverse
all the DisplayDimension objects belonging
' to the feature and grab the underlying Dimension object and query
its value.

Dim swApp As Object
Dim Part As Object
Dim Feature As Object
Dim theDimen As Object
Dim theDispDimen As Object

Sub main()
Set swApp = CreateObject ("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set Feature = Part.SelectionManager.GetSelectedObject3(1)
If (Feature is Nothing) Then
exit sub
End if

Set theDispDimen = Feature.GetFirstDisplayDimension
'*** You want to use GetSelectedObject3 here.
i = 0
While (Not theDispDimen Is Nothing)
i = i + 1
Set theDimen = theDispDimen.GetDimension
thevalue = theDimen.Value
swApp.SendMsgToUser "Dimension Value " + STR(i) + " = " +
STR(thevalue)
Set theDispDimen = Feature.GetNextDisplayDimension (theDispDimen)
Wend

End Sub
{------------------------------------------}


[Note: you want to use GetSelectedObject3]

thevalue would be the dimension value. So you would have your:

if thevalue > 1.00 then ....... else ..........

Without trying (no promises). You should be able to say:

theDimen.settext(0,"This is the Prefix")
theDimen.settext(1,"This is the Suffix")

Or if you were using const.bas, you would have the variables loaded to
use:

swDimensionTextPrefix The Prefix portion of the text
swDimensionTextSuffix The Suffix portion of the text
swDimensionTextCalloutAbove The Callout Above portion of the text
swDimensionTextCalloutBelow The Callout Below portion of the text
swDimensionTextAll The entire dimension text string (SetText only)

Instead of "0" or "1"

Please note: I've NEVER tried this but I feel comfortable with saying
that this should work.

If you need anymore help, please feel free to email me. I'm (as time
permits) able to send you simple code if you need more help.

-Dan Andrews-
Tooling Engineer
SPS Technologies

Dan Podzimek

unread,
Oct 10, 2001, 2:39:53 PM10/10/01
to
Poul,

If I unederstand your post, you can already set the prefix and suffix
but just need to retreive the actual dim value? Here's what you need
to get that value of a selected dim:

Set swApp = CreateObject("Sldworks.Application")
Set Part = swApp.ActiveDoc
Set SelMgr = Part.SelectionManager()
DimVal = Dimension.Value
' do something with the value here
' Dimension.SetText(swDimensionTextPrefix, NewPreText)
' or
' Dimension.SetText(swDimensionTextSuffix, NewSufText)


Good luck,
dp


"Poul B." <p...@12move.dk> wrote in message news:<%SXw7.296$TU1....@news.get2net.dk>...

skudfisher

unread,
Oct 10, 2001, 3:26:07 PM10/10/01
to
Hey

If you're asking what I think you're asking it should just be:

Set swDimension = swPart.Parameter("DimensionNameHere@SketchNameHere")
YourVariable = swDimension.Value

swPart is the Part or Assembly object you should have already
created and swDimension is a dimension object you're creating

Look into the dimension object in the API help for more info on
messing around with dimension objects.


"Poul B." <p...@12move.dk> wrote in message news:<%SXw7.296$TU1....@news.get2net.dk>...

Poul B.

unread,
Oct 11, 2001, 7:46:55 AM10/11/01
to
Hi guys.

Thank you for all your tips, hints and tricks - but none of them have helped
me so far. I want to be independent of feature names, configuration names
etc....I will never know dimension names, the related sketch or the feature
names.

I work on my drawing, and I simply want to get the value from an allready
inserted dimension, that I select with my pointer and a left click.

This is my "schedule":
1) Have a part, and have created a drawing.
2) Have manually made ordinate dimensions, and manually made the hole
dimensions, including threads.
3) Want to pick a diameter dimension ("highlight" it) and then press an
assigned macro button/hotkey to do this:
4) Set decimal places to zero.
5) Insert/change M as prefix to the dimension (I am able to do that)
6) Validate the value of the diameter dimension, <DIM> so I am bale to
set the postfix correct. (I am still NOT able to do that.)
7) Insert suffix to the dimension. (I am able to do that)

If this ever #6 will work, then will the text(s) for a selected dimension
for a Ø6mm cosmetic thread be changed to: M6x12, and a Ø8mm cosmetic thread
will be changed to M8x16 etc.

So - only 5) is my pain....but what a pain ;-)

'******************************** Macro below *****************************


Dim swApp As Object
Dim Part As Object

Dim boolstatus As Boolean
Dim longstatus As Long
Dim Annotation As Object
Dim Gtol As Object
Dim DatumTag As Object
Dim FeatureData As Object
Dim Feature As Object
Dim Component As Object
Dim selObj, objCount As Variant
Dim selMgr, SelDim As Object
Dim depth As Variant 'diameter 1 time

Sub M_bottom_hole()

Const swDocDRAWING = 3
Const swSelDIMENSIONS = 14
Const swDimensionTextAll = 0
Const swDimensionTextPrefix = 1 ' the text prefix
Const swDimensionTextSuffix = 2 ' the text suffix
Const swDisplayDimension = 4

Set swApp = CreateObject("SldWorks.Application")
Set Part = swApp.ActiveDoc
Set Model = swApp.ActiveDoc
Set selMgr = Part.SelectionManager()
If (Model Is Nothing) Or (Model.GetType <> swDocDRAWING) Then
MsgBox "No drawing!"
Exit Sub
End If

selType = selMgr.GetSelectedObjectType(1)

If (selType <> swSelDIMENSIONS) Then
MsgBox "No dimension selected"
Exit Sub
End If

If selMgr.GetSelectedObjectType(1) = 14 Then
Set DisplayDimension = selMgr.GetSelectedObject3(1)
'depth = InputBox("Thread depth", "Enter thread depth") ' only for
testing the suffix area
retval = DisplayDimension.GetType
depth = DisplayDimension.GetDisplayData '***** THIS, or some
sort of this - is my problem *********
retval = DisplayDimension.SetPrecision(0, 0, 0, 0, 0)
DisplayDimension.SetText swDimensionTextPrefix, "M" 'Prefix M for
metcric thread
DisplayDimension.SetText swDimensionTextSuffix, "x" + (2*depth)
'Suffix = 2 times diameter)
End If
Model.GraphicsRedraw2
End Sub

'******************************** Macro above *****************************


Best regards
Poul :-)


Poul B.

unread,
Oct 11, 2001, 7:59:48 AM10/11/01
to
Hi Dan.

Yes you're right. And it looks like a very simple code.

But I can't make SW work with the call Dimension.Value at all. The debugger
stops it every time ;-)

Best regards

Poul B.

PS: See my other posting :-)


0 new messages