Prod.: Engine, ver.: 6, ID: 60001689, HowTo : How is the transparency working in VDF

HowTo : How is the transparency working in VDF

Article60001689
TypeHowTo
ProductEngine
Version6
Date Added5/2/2012
Submitted byPter Hanios
Keywords

Subject

How is the transparency working in VDF

Summary

How is the transparency working in VDF

Solution

In version 6023 we added a new property for the vdFigure object called TransparencyMethod. This property takes values from the vdFigure.TransparencyMethodEnum like below:

TransparencyMethodEnum.ByLayer     The object takes the Transparency (AlphaBlending value) of the color of it's layer pencolor AlphaBlending.
TransparencyMethodEnum.ByBlock   The object takes the owner's color transparency (AlphaBlending value). The owner is a vdInsert that has a pencolor with AlphaBlending.
TransparencyMethodEnum.Default default value   The object takes it's own transparency value if it is True Color , If the pencolor is by index then the palette's color transparency value is used.
TransparencyMethodEnum.KeepOwn   The object always takes it's own transparency (AlphaBlending value) of the pencolor.

Beside this property there is also the Solid2dTransparency Property that is applied only to hatches/filled objects and its is applied only in 2D (Wire) mode and not in 3D (Wire3d/Shade/Hide/ShadeOn/Render)  modes. So if you want a filled object to be transparent only in 2D and not in 3D you can use this property. On the other hand if you want an object to be transparent in 3D and 2D modes then you need to use the TransparencyMethod property and also set the AlphaBlending value to the vdFigure (KeepOwn, Default) or vdLayer (ByLayer) or "parent" (vdBlock).

AlphaBlending takes values from 0 (full transparent like invisble) to 255 (not transparent at all). 
 

This How-To article applies to version 6.6023.x.x and above as the TransparencyMethod for vdFigure doesn't exist in previous that 6023 versions (see article 60001669)
 
The code below will demonstrate you how the transparency in objects work in VDF.

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        
        vdDocument doc;
        private void Form1_Load(object sender, EventArgs e)
        {
            doc = vdFramedControl1.BaseControl.ActiveDocument;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Transparency of vdCurves (line, polyline etc).
            // For better display of this transparency a thicker line type is used in the code
            doc.New();

            vdRect rect = new vdRect(doc, new gPoint(0, 0, -0.1), 10, 2, 0);
            rect.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid);
            doc.Model.Entities.AddItem(rect); // this is added just for better transparency display

            // Using the transparency in the object by setting the AlphaBlending
            vdCircle cir1 = new vdCircle(doc, new gPoint(2, 2), 1.0d);
            cir1.LineWeight = VdConstLineWeight.LW_211;
            cir1.PenColor.ColorIndex = 2;
            cir1.PenColor.AlphaBlending = 120;
            // the PenColor.AlphaBlending will be applied
            cir1.TransparencyMethod = vdFigure.TransparencyMethodEnum.KeepOwn; 
            doc.Model.Entities.AddItem(cir1);

            // Using the transparency in the Layer
            vdLayer lay = new vdLayer(doc, "Transparent");
            lay.PenColor.FromSystemColor(Color.Red); // layer is red !!!
            lay.PenColor.AlphaBlending = 120; // setting layer's transparency
            doc.Layers.AddItem(lay);
            vdCircle cir2 = new vdCircle(doc, new gPoint(4.7, 2), 1.2d);
            cir2.LineWeight = VdConstLineWeight.LW_200;
            cir2.Layer = lay;
            cir2.PenColor.ColorIndex = 2;
            // but object is not colored by layer, only transparency is by layer here
            // Layer's alpha blending wil be applied
            cir2.TransparencyMethod = vdFigure.TransparencyMethodEnum.ByLayer; 
            doc.Model.Entities.AddItem(cir2);

            // Using the transparency inside blocks/inserts
            vdBlock blk = new vdBlock(doc, "Transparecy");
            vdCircle cir3 = new vdCircle(doc, new gPoint(8, 2, 0), 1.5); // bigger circle
            cir3.PenColor.ColorIndex = 2;
            cir3.LineWeight =  VdConstLineWeight.LW_158;
            // the insert's Aplha blending will be applied
            cir3.TransparencyMethod = vdFigure.TransparencyMethodEnum.ByBlock; 
            blk.Entities.AddItem(cir3);

            cir3 = new vdCircle(doc, new gPoint(8, 2, 0), 0.7); //smaller circle
            cir3.PenColor.ByBlock = true;
            cir3.LineWeight = VdConstLineWeight.LW_158;
            // the layer's Aplha blending will be applied which isn't transparent
            cir3.TransparencyMethod = vdFigure.TransparencyMethodEnum.ByLayer; 
            blk.Entities.AddItem(cir3);

            doc.Blocks.AddItem(blk);
            vdInsert ins = new vdInsert(doc, blk, new gPoint(0, 0, 0), 0, 1, 1, 1);
            // setting the inserts draw to use the Alpha Blending
            ins.TransparencyMethod = vdFigure.TransparencyMethodEnum.Default; 
            ins.PenColor.FromSystemColor(Color.Yellow);
            ins.PenColor.AlphaBlending = 120; // setting transparency to 120
            doc.Model.Entities.AddItem(ins);

            doc.Model.ZoomExtents(); doc.Redraw(true);
        }


        private void button2_Click(object sender, EventArgs e)
        {
            // Hatches/Filled objects and Transparency
            doc.New();

            vdRect rect = new vdRect(doc, new gPoint(0, 0, -0.1), 10, 2, 0);
            rect.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid);
            doc.Model.Entities.AddItem(rect); // this is added just for better transparency display

            // 2D Transparency Does NOT work in 3D modes (hide/shade/render/wire3D)
            vdCircle cir1 = new vdCircle(doc, new gPoint(2, 2), 1.0d);
            cir1.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid);
            cir1.HatchProperties.Solid2dTransparency = 80; // values 0 (invisible)  to 255 (no transparency)
            cir1.PenColor.FromSystemColor(Color.Red);
            cir1.HatchProperties.FillColor.FromSystemColor(Color.Green);
            doc.Model.Entities.AddItem(cir1);

            // Transparency in PenColor work ALSO in 3D modes (hide/shade/render/wire3D)
            vdCircle cir2 = new vdCircle(doc, new gPoint(4.7, 2), 1.2d);
            cir2.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid);
            cir2.PenColor.FromSystemColor(Color.Green);
            cir2.HatchProperties.FillColor.FromSystemColor(Color.Red);
            cir2.HatchProperties.FillColor.AlphaBlending = 80;// values 0 (invisible)  to 255 (no transparency)
            doc.Model.Entities.AddItem(cir2);

            // the above modes can be compbined with TransparencyMethod of vdfigure (that work in 3D modes), like
            vdCircle cir3 = new vdCircle(doc, new gPoint(8, 2, 0), 1.5);
            cir3.PenColor.ColorIndex = 4;
            cir3.LineWeight = VdConstLineWeight.LW_200;
            cir3.PenColor.AlphaBlending = 80;
            cir3.HatchProperties = new vdHatchProperties(VdConstFill.VdFillModeSolid);
            cir3.HatchProperties.FillColor.FromSystemColor(Color.Green);
            cir3.HatchProperties.FillColor.AlphaBlending = 80;
            cir3.TransparencyMethod = vdFigure.TransparencyMethodEnum.KeepOwn;
            doc.Model.Entities.AddItem(cir3);

            doc.Model.ZoomExtents(); doc.Redraw(true);
        }

    }