Difference between revisions of "Lines"

From Microstation VBA Wiki
Jump to: navigation, search
(Created page with 'You can't just draw a line. Instead you have to create a line in memory and then write it to the DGN file. So in a subroutine, first you set up a variable that will hold an eleme…')
 
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
You can't just draw a line. Instead you have to create a line in memory and then write it to the DGN file. So in a subroutine, first you set up a variable that will hold an element.
 
You can't just draw a line. Instead you have to create a line in memory and then write it to the DGN file. So in a subroutine, first you set up a variable that will hold an element.
  
Then you use a very long command to make a line (see below for more info):
+
<PRE>
 
+
Dim oLine As LineElement
Then you write the line to the DGN file:
+
</PRE>
  
But to create the line you need a start and end point. So you have to set up variables that can hold those points. A point consists of three pieces of data for the X, Y, and Z coordinates. So once the point is set up, you have to store X and Y values in there and set Z to 0 (I'm always doing 2D, but it seems to work better with 3D points):
+
You also must define two [[Points]] and set the values in the X,Y, and Z directions:
  
 
<PRE>
 
<PRE>
Dim ptStart, ptEnd as point3d
+
Dim ptStart As Point3d
 
+
Dim ptEnd As Point3
 
ptStart.X = 10
 
ptStart.X = 10
 
ptStart.Y = 10
 
ptStart.Y = 10
 
ptStart.Z = 0
 
ptStart.Z = 0
ptEnd.X = 10
+
ptEnd.X = ptStart.X
 
ptEnd.Y = 20
 
ptEnd.Y = 20
ptEnd.Z = 0
+
ptEnd.Z = ptStart.Z
 +
</PRE>
 +
 
 +
Then you create a line element and add it to the design file:
 +
 
 +
<PRE>
 +
Set oLine = CreateLineElement2(Nothing, ptStart, ptEnd)
 +
ActiveModelReference.AddElement MyLine
 +
</PRE>
 +
 
 +
==Line Characteristics==
 +
 
 +
Some settings are pretty easy, able to be set by changing values of properties in ActiveSettings (color numbers are part of Microstation; 0 is white; 1 is blue; 3 is red). When you create a line, all of the ActiveSettings will be used, so to get what you want (instead of whatever the current ActiveSetting is) you need to set all of the characteristics you want:
 +
 
 +
<PRE>
 +
ActiveSettings.Color = 0
 +
ActiveSettings.LineWeight = 3
 +
</PRE>
 +
 
 +
But since there are an infinite number of levels and they are named, you can't change levels quite that easily. First you have to set up a Level variable, then you can assign a level to it by looking for the name of the level (by default, levels are named "Level 1," "Level 2," etc.)
 +
 
 +
<PRE>
 +
Dim oLevel as Level
 +
Set oLevel = ActiveDesignFile.Levels.Find("Level 2")
 +
Set ActiveSettings.Level = oLevel
 
</PRE>
 
</PRE>
 +
 +
The Line Style (solid, dashed, centerline, etc.) is the same way as Levels. You have to set up a variable of the LineStyle type, then store the settings in it using Find and then set the ActiveSettings by using your variable. To set the active LineStyle to 2 you must do the following:
 +
 +
<PRE>
 +
Dim oLineStyle As LineStyle
 +
Set oLineStyle = ActiveDesignFile.LineStyles.Find("2")
 +
Set ActiveSettings.LineStyle = oLineStyle
 +
</PRE>
 +
 +
I set all of this up by making up a subroutine called [[SetLine]], where I could enter a string representing the type of line I wanted and the subroutine would take care of all of the settings. If I want a line that represents a dimension line I put this in my code:
 +
 +
<PRE>
 +
SetLine("Dimension")
 +
</PRE>
 +
 +
And the level, line weight, line style, and color are all changed by the subroutine.

Latest revision as of 21:55, 26 May 2011

You can't just draw a line. Instead you have to create a line in memory and then write it to the DGN file. So in a subroutine, first you set up a variable that will hold an element.

Dim oLine As LineElement

You also must define two Points and set the values in the X,Y, and Z directions:

Dim ptStart As Point3d
Dim ptEnd As Point3
ptStart.X = 10
ptStart.Y = 10
ptStart.Z = 0
ptEnd.X = ptStart.X
ptEnd.Y = 20
ptEnd.Z = ptStart.Z

Then you create a line element and add it to the design file:

Set oLine = CreateLineElement2(Nothing, ptStart, ptEnd)
ActiveModelReference.AddElement MyLine

Line Characteristics

Some settings are pretty easy, able to be set by changing values of properties in ActiveSettings (color numbers are part of Microstation; 0 is white; 1 is blue; 3 is red). When you create a line, all of the ActiveSettings will be used, so to get what you want (instead of whatever the current ActiveSetting is) you need to set all of the characteristics you want:

ActiveSettings.Color = 0 
ActiveSettings.LineWeight = 3

But since there are an infinite number of levels and they are named, you can't change levels quite that easily. First you have to set up a Level variable, then you can assign a level to it by looking for the name of the level (by default, levels are named "Level 1," "Level 2," etc.)

Dim oLevel as Level
Set oLevel = ActiveDesignFile.Levels.Find("Level 2")
Set ActiveSettings.Level = oLevel

The Line Style (solid, dashed, centerline, etc.) is the same way as Levels. You have to set up a variable of the LineStyle type, then store the settings in it using Find and then set the ActiveSettings by using your variable. To set the active LineStyle to 2 you must do the following:

Dim oLineStyle As LineStyle
Set oLineStyle = ActiveDesignFile.LineStyles.Find("2")
Set ActiveSettings.LineStyle = oLineStyle

I set all of this up by making up a subroutine called SetLine, where I could enter a string representing the type of line I wanted and the subroutine would take care of all of the settings. If I want a line that represents a dimension line I put this in my code:

SetLine("Dimension")

And the level, line weight, line style, and color are all changed by the subroutine.