Insunits and associates

Insunits and associates

Anonymous
Not applicable
541 Views
6 Replies
Message 1 of 7

Insunits and associates

Anonymous
Not applicable
I am very new to VBA, ie. I have yet to write any code.

Does anyone have any code that sets InsUnits, InsUnitsDefTarget and InsUnitsDefSource all to the same value, when one of the values is set manually ?

For example, say I wanted to set InsUnits to the value of 6, it would then automatically set the values of InsUnitsDefTarget and InsUnitsDefSource to 6 also.

I know I can set all these values manually, but what's the point if I can get the code to do it for me?

I presume that this code would be fairly simple to do, but I am just starting out on the road to learning VBA, and I think this would be a good starting point.

Any help would be greatly appreciated.
0 Likes
542 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
Have a look in the help file for SysVarChanged and SetVariable they both have an example that should get you started.

Regards - Nathan
0 Likes
Message 3 of 7

Anonymous
Not applicable
Thanks for the input Nathan.
I have trawled through the help files but I keep going round and round in circles. I can get the 2 separate pieces of code to work side by side but I have yet to 'glue' them together in the way that I would like to.
I'm a complete novice at this; so if you or anyone else can help a little more, that would be great.
0 Likes
Message 4 of 7

Anonymous
Not applicable
It may not be as simple as it sounds.

If you are trying to change other system variables inside of the
SysVarChanged event you are causing the SysVarChanged event to call itself
... a recursion for lack of a better term. The results will be unpredictable
and may cause system lock-up.

See the Guidelines for Writing Event Handlers in VBA help.

Gary
0 Likes
Message 5 of 7

Anonymous
Not applicable
You are correct due to the fact that the event fires regardless of whether the new value is the same as the old.

I think what he wants to do is possible though so I will look at it further.

Regards - Nathan
0 Likes
Message 6 of 7

Anonymous
Not applicable
The following works and I don't think should create any problems.

[code]
Private Sub objAcadApp_SysVarChanged(ByVal SysvarName As String, ByVal newVal As Variant)
If SysvarName = "INSUNITS" Then
If ThisDrawing.GetVariable("INSUNITSDEFSOURCE") newVal Then ThisDrawing.SetVariable "INSUNITSDEFSOURCE", newVal
If ThisDrawing.GetVariable("INSUNITSDEFTARGET") newVal Then ThisDrawing.SetVariable "INSUNITSDEFTARGET", newVal
End If
If SysvarName = "INSUNITSDEFSOURCE" Then
If ThisDrawing.GetVariable("INSUNITS") newVal Then ThisDrawing.SetVariable "INSUNITS", newVal
If ThisDrawing.GetVariable("INSUNITSDEFTARGET") newVal Then ThisDrawing.SetVariable "INSUNITSDEFTARGET", newVal
End If
If SysvarName = "INSUNITSDEFTARGET" Then
If ThisDrawing.GetVariable("INSUNITSDEFSOURCE") newVal Then ThisDrawing.SetVariable "INSUNITSDEFSOURCE", newVal
If ThisDrawing.GetVariable("INSUNITS") newVal Then ThisDrawing.SetVariable "INSUNITS", newVal
End If
End Sub
[/code]

Regards - Nathan
0 Likes
Message 7 of 7

Anonymous
Not applicable
thank you very much for your help Nathan, it is much appreciated.

here is my attempt at the code:

Public Sub Example_SetVariable()
Dim retVal As String
Dim SysvarName As String
Dim sysVarData As Variant
Dim DataType As Integer
' Set INSUNITS system variable (data type Integer) to 6. NOTE that
' you need to declare a variable as the data type of system variable,
' assign data to that variable and then make it variant type
retVal = ThisDrawing.Utility.GetString _
(1, vbCrLf & "Enter the Value of InsUnits (This will also change InsUnitsDefSource & InsUnitsDefTarget to the same Value): ")
Dim intData As Integer
SysvarName = "INSUNITS"
intData = retVal
sysVarData = intData ' Integer data
ThisDrawing.SetVariable SysvarName, sysVarData

' Check the variable using GetVariable
sysVarData = ThisDrawing.GetVariable(SysvarName)
MsgBox SysvarName & " = " & sysVarData, , "SetVariable Example"
SysvarName = "INSUNITSDEFSOURCE"
ThisDrawing.SetVariable SysvarName, sysVarData
SysvarName = "INSUNITSDEFTARGET"
ThisDrawing.SetVariable SysvarName, sysVarData

End Sub
0 Likes