C++ and the Unreal API

Of course, I’d fall in love with Unreal as a C# programmer. I mean, who doesn’t want to take the most difficult path to everything, am I right? Since I refuse to let my obsession of Unreal go away (primarily due to its volume effects and lighting/sky system), I’ve decided to dive into their API trying to understand the architecture while grasping the nuances of C++. Thankfully, the basics of C++ and C# aren’t that different. I can read the C++ language. That wasn’t the case when I went from Lisp to C#. That alone puts me light years ahead of where I was when I started with C#. For example, I didn’t expect to be able to understand the tutorial I followed to construct a C++ Unreal project with a pickup system and custom blueprint in a matter of a few hours. I noticed I essentially struggle with the details in C++ that I would struggle within C#. Great news because those challenges others often run into and generally get solved with a little research or asking questions in forums; this tells me that for me understanding the structure of a language is probably more important than understanding the specific details for every aspect of it.

The system I constructed involves a C++ project using the First Person Template. The person walks around picking up industrial-like barrels. I began the project using Unreal Engine 4.22. Since the tutorial I found was about four years old, the code had to be modified/corrected due to API changes over the years.

industrial barrels

The first step was to generate a new class in the editor.

editor

After that it was a matter of locating the correct classes to include and adding the text in the below images to the header (.h) and cpp files.

header

cppfile.JPG

In a few hours, I completed the task I set out to do and am confident that I can dive and start to push things considerably further. It took me a few years with C# and various APIs before I got to that same level of confidence. Since I can’t up and quit my career to find a mentor, I pursue this stuff on my own.  Because of that, I was hesitant to dive into something new.  Don’t get me wrong, I understand that C++ is considerably different than C#, but realizing the differences and having accomplished my first task using the Unreal Engine API quickly enough makes me more excited to dive in.

Dynamo for Civil 3D Part 4 – Node Colors

Personalizing content is often why people dive into customization.   I noticed a few examples online with different colors for their nodes in Dynamo.  It turns out we can adjust the theme and colors by altering the DynamoColorsandBrushes.xaml file here: Autodesk 2019\AutoCAD 2020\C3D\Dynamo\Core\UI\Themes\Modern. Unfortunately, to see the updates we have to close out Dynamo and Civil 3D then reopen them both.

example

Dynamo for Civil 3D Part 3

It was a bit of a speed bump to figure out the proper way to work between the Autocad and Civil 3D API through the Dynamo interface, but I’m there, and I love it. The information people have made available online is convoluted, difficult to understand, and frankly filled with unnecessary work (maybe even errors, misdirection). Perhaps they don’t understand they are making it harder than it needs to be.  Locating the libraries and understanding what the limits and capabilities of the Dynamo version of its “objects” took some time, but realizing that it’s not necessary to convert objects from Civil 3D types to Dynamo types and that I can use typical extensions and the API as is opened my eyes to a whole new world of visual programming. Now, with the ability to use the visual aspects of the node-based system, I can combine the power and functions of Dynamo with coding through Visual Studio to generate endless, scalable, dynamic, ever-growing procedural and generative designs.  You ever see something so big in your head it looks like a giant white whale, and wonder can you tackle it, or should you give up before it kills you?

potential

Dynamo for Civil 3D

I used Dynamo for Civil3D for the first time.  I love that I don’t have to close Civil 3D constantly just to load and test code, and after writing hundreds of thousands of lines of code over the years it’s exciting to not have to dig through a few hundred for simple actions.  There is an enormous amount of power in its parametric abilities right away, as demonstrated by the Autodesk’s team themselves, but I’m excited to try and use it for production and geometrical challenges.

example

#UnrealEngine, My New Favorite Thing

I absolutely LOVE Unreal Engine.  Of course I would, because I love C#.  Why wouldn’t I love the program built for C++ users when there’s an alternate, more popular viable option for C# writers. I don’t care. A guy can’t help who he falls in love with and this adventure will fall in line with everything other thing in my life (choosing the hardest possible path to my objective).

Tweaking a few materials online I was able to generate a pretty cool fading and rotating emissive material.   Looks like a Predator / Star Trek type armor shield or something. Probably completely useless for anything I’ll ever do (unless I get a night visual project in Vegas where Neon lights struggle for power XD). Still, was fun to play with.

example1.PNG

example2

Zbrush

Adding a section on Zbrush. First post covers the curves helper plugin. Using this plugin is the simplest way to generate wires, cables, curves, rope and more for ZBrush.  To use the plugin all we have to do is use ZSpheres to construct our path and then select the generate button. This will trace the center of the ZSphere path.  After that we select a subtool and then choose the option to create the curve.  You can read about it more here:

http://www.zbrushcentral.com/showthread.php?208308-Useful-small-ZScripts-and-Macros-for-ZBrush-4R8&p=1222584&viewfull=1#post1222584

Only reason I am posting is because this is one of those trade secrets artists don’t like giving away so finding it in the first place was a major pain in the rear.  Hopefully I dropped in enough keywords in this that other people won’t have the same problem.

Computer Vision, ReCap, and Photoshop

Google generates their surface for Google Earth using a concept called computer vision.  Those of us not on the infinite-internet-funded budgets don’t have the pleasure of using that costly equipment but essentially the computers semi-automate the construction of a 3D surfaces, or meshes from flights.  The tech has advanced enough that mapping materials and textures has become more streamlined as well.  The rest of are stuck with a more budget-friendly (and labor intensive) approach to generating a 3D surface for our modeling and presentation purposes.   ReCap is software developed by Autodesk that can help to generate computer models from aerial photography, especially useful for someone with a a drone and the right permits.  Permitting for urban areas of major cities can be delayed by a year or more though, so many of us resort to manually modeling our surfaces the best we can in time constraints using whatever methods we can. One such method is using Recap and Google Earth.  By recording a 360-degree video rotating a surface in google earth we can convert those video frames to images and upload them to ReCap for processing.  Manually modeling high-priority buildings is best, but for low levels of detail (outlining areas and background), this has potential.  During my escapades I found Photoshop opens videos, allows me to crop them however I wish, and then render the frames to images. There are other methods but the simplicity in cropping and converting has made this my favorite.

 

export

 

 

Tutorials

I’ve decided to start adding tutorials again.  Tutorials are difficult for several reasons. First, there’s time. Simply put, it really does fly by, and before I can create one, I’ve already lost the time to do it. Second, those of us who make tutorials or train throw ourselves out there, and in competitive environments, this leads to a multitude of responses, not all of them pleasant. So, we build thicker skin.  Finally, with literally thousands upon thousands of videos out there covering software like 3ds Max, Civil 3d and Autocad, it’s difficult to find a reason.  My reason: I find that I may know something really well, but when presenting it, I always learn a little bit more.  So, over the next year I’ll be covering several topics in no particular order.  I hope a few are found reasonably useful.

Took me a while to figure out a clean way to generate this blueprint-like effect using the OSL Shaders in 3ds Max.

BluePrint

 

If you’re interested in 3ds Max with OSL (Open Shading Language) you can download this scene to practice with here:  https://lnkd.in/gZbVbqS

Robot

 

I created a template with the Physical Material presets. You’ll need to add your own light source.  Feel free to download it here: https://lnkd.in/gC8tfM2

Materials.jpg

 

Here is a cheat sheet for new 3ds Max users:

Download

CHEATSHEET

 

Tutorial A – Setting up real-time rendering with 3ds Max and the VRAY RT system https://youtu.be/nZ6QKMIl0kU

RT

Tutorial 1 – Character Creation for the non-character creator types https://youtu.be/GUgFxDa-aD8

funny dude

Tutorial 2 – Basic example of using Substance Painter with 3ds Max in a way that might be useful for architectural and engineering visualization https://youtu.be/QwBT894XHSk

cello

Tutorial 3 – This tutorial demonstrates how render elements in 3ds Max can allow us to export various channels to make images more appealing (specifically for engineering / architectural visualization).  https://youtu.be/kL5ORk9CbMY

birdyshot

Tutorial 4 – Quick demonstration using Vray lights with 3ds Max. https://youtu.be/WwiAH75DlhQ

vray

Tutorial 5 – OpenSubDiv with Crease modifier, bend, lattice, FFD 4X4X4 and symmetry.  https://youtu.be/P5RcHL1rD1U

modifiers

Customization for Autocad, Civil 3D, and 3ds Max

Below are various thoughts / notes concerning customization of software and languages I use on a consistent basis. In most cases this includes Maxscript for 3ds Max and Autolisp / C#.Net for Autocad and Civil 3D.

It’s possible to edit the visibility states of dynamic blocks using c# .net.  For the flip state it was particularly tricky to deal with the short value.  I found by simply converting the object to a string I was able to easily swap between the states I wanted.  The code is below:

[code language=”csharp”]
DynamicBlockReferencePropertyCollection pc = br.DynamicBlockReferencePropertyCollection;
foreach (DynamicBlockReferenceProperty prop in pc)
{
if (prop.PropertyName.ToUpper().Contains("FLIP"))
{
object[] allowedValues = prop.GetAllowedValues();
if (prop.Value.ToString() == "1")
prop.Value = allowedValues[0];
else
prop.Value = allowedValues[1];
}
}

[/code]

1) I created a cheat sheet to help those learning the API for Civil 3D. You’re welcome to download it here:  Pro-Cad Civil 3D 2018 C-Sharp Net Cheat Sheet 

cheatsheet
2) Three reasons to learn to code:

Influence the Future – Imagine yourself born in 1452. Without a formal education you venture out to make a life. Instead, you shape the world. That’s exactly what Leonardo da Vinci did. He became the leader at the forefront of technology, shaping the world that followed. Da Vinci kept a massive journal filled with his ideas and sketches. He didn’t know his work would influence the world for centuries to come. Imagine the internet your journal, you are Da Vinci, and your code could do the same thing. “It had long since come to my attention that people of accomplishment rarely sat back and let things happen to them. They went out and happened to things.” – Leonardo da Vinci

A Challenge Worth Tackling – People refered to Da Vinci as a quiet man of science. Society called him a peaceful man, who did not approve of conflict and war. Yet, he understood the ‘bestialissimapazzia’ (most bestial madness) of war had two sides. The challenge he tackled was to protect his fellow man. He sought to maintain liberty from tyrants who would besiege them and their towns. Driven by a cause, he proceeded to investigate ways to protect them. This led to his studies into machinery and flight centuries ahead of its time. In the coding world there are two sides to the war. One is automation will replace humans and the quality of society will plumit. The opposing view is coding will lead to improvements by allowing people to focus on being more creative and caring. It’s a choice to believe one or the other, and coding isn’t going away. ” Every action needs to be prompted by a motive” – Leonardo da Vinci

Improve Life – Da Vinci noted that simplicity is the ultimate sophistication. He ventured to improve the lives around him while studying and learning what he loved. He found the two functions were the same. In the end, if our efforts help to make one or two lives more easier to manage, it’s an improvement. Chances are, if you are reading this, you have a fetish for Da Vinci or you are interested in coding. I can’t help with the former but the latter is shaping the world as we know it, we just need to get on bored. “A painter was asked why he had made his children so ugly, when his figures which were dead things he had made so beautiful. His reply was that he made his pictures by day and his children at night.” – A Joke by Leonardo da Vinci

The sharp symbol in C# is a reference to the music note, and that it combines four + symbols to create it.

3) General Resources

Coding Haven – http://www.c-sharpcorner.com/technologies/csharp-programming

Civil 3D/Autocad

Development Guide – http://help.autodesk.com/view/CIV3D/2017/ENU/?guid=GUID-275A6271-7758-4C14-9703-989B1B007E3E

3ds Max

CGSchool Maxscript Cheat Sheet – http://www.thecgschool.com/downloads/3DATS_MAXScript_Cheat_Sheet.pdf

4) Using C# .Net with Autocad or Civil 3D it’s easy to dynamically construct a winform and datagridview to display information we might want inside a drawing.  This example demonstrates how to do that by listing the number of objects inside the BlockTableRecord for modelspace.

[code language=”csharp”]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System.Linq;
using System.Windows.Forms;

namespace Autocad_DataGridView
{
public class Class1
{
[CommandMethod("acadgridview")]
public void routine()
{

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(modelSpaceId, OpenMode.ForRead) as BlockTableRecord;

Form form = new Form();
form.Width = 300;
form.Show();

DataGridView MyDataGridView = new DataGridView();
MyDataGridView.Anchor = AnchorStyles.Top;
MyDataGridView.Width = form.Width;
MyDataGridView.Height = form.Height;
MyDataGridView.Columns.Add("Column 1", "Objects In Model Space");
MyDataGridView.Rows.Add(btr.Cast<ObjectId>().Count().ToString());
MyDataGridView.Columns[0].Width = form.Width;
form.Controls.Add(MyDataGridView);

}
}
}
}
[/code]

5) Everything we program in regards to Civil 3D or Autocad requires we collect and work with data. In some cases we wish to produce reports and tables of information. Using C# with the Civil 3D API we can do this on the fly. Below is an example. First I create a form dynamically. Then I collect the layers (SymbolTable) where I add columns for the layer name and the layer color.  Next, I iterate through the layers in the Symbol Table and add them to the DataTable that was created dynamically.  Finally, I create a DataGridView to display the information I stored in the DataTable, since the DataTable can’t be displayed in it’s native format.

[code language=”csharp”]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System.Windows.Forms;

namespace Autocad_DataTable
{
public class Class1
{
[CommandMethod("acaddatatable")]
public void routine()
{

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
Form form = new Form();
form.Width = 300;

SymbolTable symboltable = (SymbolTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);

System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.Add("Layer Name");
dt.Columns.Add("Layer Color");

foreach (ObjectId id in symboltable)
{
LayerTableRecord symbol = (LayerTableRecord)tr.GetObject(id, OpenMode.ForRead);

System.Data.DataRow dr = dt.Rows.Add();
dr["Layer Name"] = symbol.Name;
dr["Layer Color"] = symbol.Color.ToString();
}

DataGridView grid = new DataGridView();
form.Controls.Add(grid);
grid.DataSource = dt;
form.Show();
}
}
}
}
[/code]

6) One of the most important parts of customization is optimization. For example, if we want to change some featurelines we don’t want to iterate through the drawing’s entire database. Instead, we  filter everything out and start with the featurelines.  Eventually we drill down until we get those we want to modify, but to begin we use selection filters (shown here: Dev Guide Link).  In order to use selection filters we need to know the DXFCode (or DXF Name) of the object we wish to select. One way find this out is to cast the modelspace objects to a list, then print a list of those objects dxf names to the screen using a  DataGridView as shown in the example below.

dxfnames

[code language=”csharp”]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using System.Linq;
using System.Windows.Forms;

namespace Autocad_DataGridView
{
public class Class1
{
[CommandMethod("acaddxftotal")]
public void routine()
{

Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;

using (Transaction tr = db.TransactionManager.StartTransaction())
{
ObjectId modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(modelSpaceId, OpenMode.ForRead) as BlockTableRecord;

Form form = new Form();
form.Width = 700;
form.Show();

System.Collections.Generic.List<string> dxfnames = new System.Collections.Generic.List<string>();

DataGridView MyDataGridView = new DataGridView();
MyDataGridView.Anchor = AnchorStyles.Top;
MyDataGridView.Width = form.Width;
MyDataGridView.Height = form.Height;
MyDataGridView.Columns.Add("Column 1", "DXF Names");
System.Collections.Generic.List<ObjectId> modelspaceobjects = btr.Cast<ObjectId>().ToList();
foreach (ObjectId modelobjectid in modelspaceobjects)
{
dxfnames.Add(modelobjectid.ObjectClass.DxfName.ToString());
}

System.Collections.Generic.List<string> distinctdxfnames = dxfnames.Distinct().ToList();
foreach (string dxfname in distinctdxfnames)
{
MyDataGridView.Rows.Add(dxfname);
}
MyDataGridView.Columns[0].Width = form.Width;
form.Controls.Add(MyDataGridView);

}
}
}
}
[/code]

7) Link to probably the best example of using linq with autocad: Linq and the Autocad Net API

8) Several years ago I decided to abandon the two script / program languages I was using and forced myself to learn a new one (just to see if I could really). That was C# (C-Sharp). This chart shows that it’s top of the line to take of the world. Lotto XD

CcVyDI9UsAA0RQp.jpg large

9) A completely useless app but I had fun developing it. If you want it just message I’ll send it your way.

10) Here’s a cool idea.  With the ability to use animated gifs in picture boxes we can develop training applications in CAD for specific workflows.  Check out an animated interface I created here: https://www.youtube.com/watch?v=y391aP_jCeE&feature=youtu.be&vq=hd720