AnyLogic Professional enables users to import CAD drawings (in DXF format) into their presentations. You may need this in the case your model concerns a movement of objects (agents, pedestrians, etc.) in a certain physical space defined using a CAD drawing. Usually CAD drawings contain layouts of some buildings (hospitals, factory floors, stadiums, museums, etc.), or even some streets.
There are two modeling approaches where CAD drawings are applied in most cases: network based modeling and pedestrian dynamics modeling.
- In network-based modeling you may need to draw a network of nodes and segments defining the movement of agents and resources between some important areas marked on your drawing. In this case you can simply import this CAD drawing into your model and then mark it up with rectangles and polylines defining network nodes and segments.
- In pedestrian dynamics modeling you may need to simulate how pedestrians move through some building whose layout you have at your hands in DXF format. In this case you again import this CAD drawing into your model’s presentation and then draw the building walls, obstacles, and, optionally, some service points and queues on top of it.
To add a CAD drawing
- Drag the CAD Drawing element from the Presentation palette into the graphical editor.
- Go to the Properties and choose CAD drawing file you want to be displayed on the presentation. Add a drawing by clicking the Browse button. This opens the Open dialog box. Browse for the file you want to add, then select it and click Open when finished. You will see the name of the selected file in the File edit box.
- After choosing the file, you can go to the File reading log section and view the information on reading the selected drawing file: which layers were read successfully, and which were not.
- Go to the Layers section. In the table you can customize the set of layers that will be visible on the drawing at runtime. To show a layer, select the check box in the corresponding row of the table.
- Optionally, you can change the Fill color for the drawing and Invert default colors by selecting the checkbox of the same name.
CAD drawing file added onto AnyLogic presentation will be copied to the model folder. In case you copy your model elsewhere all files will be copied as well. It will also automatically appear in the model’s Resource folder in the Projects view. This way you will be able to track the current state of the source file, switch between the absolute and relative file paths, etc.
To convert a CAD drawing to AnyLogic markup
After adding a CAD file to the diagram, you can transform it into a multitude of wall elements. The layout of these walls will be identical to the layout depicted in a CAD file, albeit some adjustments might be required.
For this functionality to work, the CAD file must be specified in the File edit box in the CAD Drawing element’s properties.
- Right-click the CAD Drawing element in the graphical editor and select Convert to Markup in the context menu.
The CAD Converter dialog will open up.
In the left list, select the checkboxes corresponding to the CAD file layers you want to convert.
- In the Choose markup type drop-down list, select a markup element you want to get in the output. As of now, the only possible option is the wall element. More will be added in the future.
- Select the Hide layer after convert if you want the CAD Drawing layers you have selected for conversion to become invisible on the diagram. They will remain in the model, and you can switch their visibility on in the CAD Drawing element’s properties.
- Click Finish.
In case the source file contains intricate markup (and a huge number of markup elements will be generated upon conversion), AnyLogic displays a message warning you about a possible performance issue. You may then select to proceed or cancel the operation.
The resulting layout of markup elements will appear in the graphical editor. The source CAD Drawing element will remain on the diagram. You can use it as a reference for further adjustments.
Name — The name of the CAD shape. It is used to identify and access the shape from code.
Ignore — If selected, the CAD drawing is excluded from the model.
Visible on upper agent — If selected, the shape is also visible on the upper agent where this agent lives.
Lock — If selected, the shape is locked. Locked shapes do not react to mouse clicks — it is impossible to select them in the graphical editor until you unlock them. It is frequently needed when you use a shape as a background image for your animation and you want to prevent editing this shape while drawing other shapes over it.
Visible — If selected, the shape is visible on the presentation at model runtime.
File — The path to the CAD drawing file. You can choose the CAD file using the Browse button. The button to the right allows to switch between the absolute and relative file path. After choosing the file, you can open the File reading log section of the properties and view the information on reading the selected drawing file: which layers were read successfully, and which — not.
Browse — The button allows user to browse to the required CAD drawing file.
Fill color — Here you can choose the fill color for the drawing.
Invert default colors — Select this checkbox if you want to invert the default colors of the drawing.
Here you can customize the set of CAD layers that will be visible on the drawing. To show a layer, select the check box in the corresponding row of the table.
- Position and size
Level — Level to which this element belongs.
X — X-coordinate of the upper left corner of the CAD shape.
Y — Y-coordinate of the upper left corner of the CAD shape.
Width — The width of the CAD drawing shape, in pixels.
Height — The height of the CAD drawing shape, in pixels.
On click — Here you can type Java code that will be called each time a user clicks on the shape at the model runtime. If there are several shapes overlapping in the click point, the click will interact with the topmost shape only.
self — the element itself.
clickx — x-coordinate of the click relative to the shape coordinates.
clicky — y-coordinate of the click relative to the shape coordinates.
Use antialiasing — AnyLogic presentation supports anti-aliasing — one of the most important techniques in making graphics more smooth and pleasing to the eye. Anti-aliasing is a process of smoothing the drawing of points or lines that would otherwise appear jagged. However, note that more time is spent on rendering the presentation with the anti-aliasing set. Select the checkbox to turn on the antialiasing for this CAD drawing.
Show name — If selected, the name of the CAD shape will be displayed on the presentation diagram.
- File reading log
Here you can view information on reading the selected drawing file: which layers were read successfully, and which were not (of course, this information is available only after choosing the drawing file in the File property).
- Shape position
Function Description double getX() Returns the X coordinate of the shape (namely, the X coordinate of its upper left corner). double getY() Returns the Y coordinate of the shape (namely, the Y coordinate of its upper left corner). void setX(double x) Sets the X coordinate of the shape.
x — the new value of X coordinate.
void setY(double y) Sets the Y coordinate of the shape.
y — the new value of Y coordinate.
void setPos(double x, double y) Sets new coordinates for the shape.
x — the new value of x coordinate.
y — the new value of y coordinate.
- Shape size
Function Description double getWidth() Returns the width of the shape. double getHeight() Returns the height of the shape. void setWidth(double width) Sets the width of the shape equal to width. void setHeight(double height) Sets the height of the shape equal to height.
- Working with layers
Function Description String getLayerNames() Returns the array of layer names in this CAD.This array shouldn’t be modified by user. void setVisibleLayers(String ... layerNames ) Makes the layers with given names visible and hides all other layers in this CAD. Throws an error if layer(s) with the given name isn't found. To show all the layers, please call setVisibleLayers(getLayerNames()).
layerNames — visible layer names.
void setLayerVisible(String layerName, boolean visible) Makes the layer with the given name visible/invisible.
Throws an error if layer with the given name isn’t found.
layerName — the name of the layer.
visible — new visibility state of the layer.
boolean isLayerVisible(String layerName) Returns true if the layer with the given name is visible, otherwise returns false. Returns false if layer with the given name isn’t found.
layerName — the name of the layer.
Color getCustomLayerColor(String layerName) Returns custom color of the layer’s shapes, if the one is defined. Otherwise returns null. Returns null if layer with the given name isn’t found.
layerName — the name of the layer.
void setCustomLayerColor(String layerName, color) Sets custom color for all the shapes for the given layer. The value of null indicates that layer will be drawn using its default color(s). Throws an error if layer with the given name isn’t found.
layerName — the name of the layer.
color — the value of custom layer color, or null
- Background color
Function Description Color getBackgroundColor() Returns the background color. void setBackgroundColor(Color backgroundColor) Sets the background color.
backgroundColor — the new background color.
- Image file name
Function Description String getImageFileName() Returns the file name of the CAD drawing.
- Shape visibility
Function Description boolean isVisible() Checks the visibility of the shape. If the shape is visible, returns true, otherwise returns false. void setVisible(boolean v) Sets the visibility of the shape.
v — visibility: if true — the shape is set to be visible, if false — not visible.
- Points inside the shape
Function Description boolean contains(double px, double py) Test if the shape contains the point with the given coordinates (relative to this shape’s container, i.e. in the same system with the coordinates of this shape, x and y) . Returns true if the shape contains the point with the given coordinates.
px — the x coordinate relative to this shape’s container.
py — the y coordinate relative to this shape’s container.
Point randomPointInside() Returns the randomly chosen point inside the shape area.
This function utilises Random Number Generator of the Presentable object containing this shape. (Will throw an exception if the shape has been created from code and hasn't been added to any group, — in this case use randomPointInside(Random rng)).
Point randomPointInside(java.util.Random rng) Returns the randomly chosen point inside the shape area. This function utilises the given Random Number Generator.
rng — the random number generator.
How can we improve this article?