How to set layer state in Civil 3d to current document using c#?

How to set layer state in Civil 3d to current document using c#?

swarali_kulkarni4KMYK
Alumni Alumni
1,134 Views
12 Replies
Message 1 of 13

How to set layer state in Civil 3d to current document using c#?

swarali_kulkarni4KMYK
Alumni
Alumni

I want to select layer state, based on the layer state the particular layer state should set to the current document. can any one has worked on same or anybody know about it can post the answer 

0 Likes
Accepted solutions (1)
1,135 Views
12 Replies
Replies (12)
Message 2 of 13

shubhamraut221195
Enthusiast
Enthusiast
Message 3 of 13

swarali_kulkarni4KMYK
Alumni
Alumni

Thank you for the reply.

But here http://docs.autodesk.com/ACD/2010/ENU/AutoCAD%20.NET%20Developer%27s%20Guide/index.html?url=WS1a9193...I unable to select individual layer state. In Restore command we can get preview of individual layer state . But I am not getting what should I select in parameter 4- Layer settings are restored as viewport overrides(4th parameter in method -RestoreLayerState (1,2,3,4)  ). If any one knows or already works can post

0 Likes
Message 4 of 13

shubhamraut221195
Enthusiast
Enthusiast

@swarali_kulkarni4KMYK ,

Suppose you have layer state 'ABCD' in your drawing and if you use following block of code, it will restore the values of LayerStateMasks that you have mentioned. 

string sLyrStName = "ABCD";
if (acLyrStMan.HasLayerState(sLyrStName) == true)
{
acLyrStMan.RestoreLayerState(sLyrStName,
ObjectId.Null,
1,
LayerStateMasks.LineWeight);
}

 

In above code, LayerStateMasks.LineWeight will restore the value of lineweight to the value defined in layer state. You can add more LayerStateMasks in the same if you want other properties to be changed as well.

Message 5 of 13

swarali_kulkarni4KMYK
Alumni
Alumni

Is this will work for selection of layer state?

0 Likes
Message 6 of 13

shubhamraut221195
Enthusiast
Enthusiast

Selection of Layer state means? Can you elaborate?
Do you mean you have more than one layer states and you want to select one of them and restore?

Message 7 of 13

swarali_kulkarni4KMYK
Alumni
Alumni

I appreciate your interest in finding solution.

 

Yes, exactly. There are multiple layer states in current document. I want to select any one from them. So i am trying to use restore method to select layer state. will it work?

0 Likes
Message 8 of 13

shubhamraut221195
Enthusiast
Enthusiast

Yes it is possible. You can read layer states in current drawing. You can read layer states in current drawing and add those in prompt for user to select. Use following block of code. It will read layer states in current drawing and show them as keywords to user. User can select those layer states.

 

 

ArrayList layerStates = acLyrStMan.GetLayerStateNames(false, false);
            PromptKeywordOptions opts = new PromptKeywordOptions("Select layer state");
            for(int i=0;i< layerStates.Count; i++)
            {
                opts.Keywords.Add(layerStates[i].ToString());
            }
            PromptResult result = ed.GetKeywords(opts);
            if(result.Status == PromptStatus.OK)
            {
                if (acLyrStMan.HasLayerState(result.StringResult) == true)
                {
                    acLyrStMan.RestoreLayerState(result.StringResult,
                                                 ObjectId.Null,
                                                 1,
                                                 LayerStateMasks.LineWeight);
                }
            }

  

Message 9 of 13

We have list of layer states in current document, We have to implement the functionality where based on layer state selection  we have to restore that layer state. Please check screenshot. I have tried RestoreLayerState(LayerstateName,ObjectId.Null,1,LayerStateMasks.LineWeight). No Objects are getting selected. Here once click on restore every layer state get selected and set to the current document. Same I want to implement but layer state not getting added  to current document by using restore method.

 

swarali_kulkarni4KMYK_4-1686661123499.png

Otherwise I have to implement 

swarali_kulkarni4KMYK_0-1686661598226.png

Same as per above. after selecting any layer state here, on document also has to reflect same changes as per layer state as already implemented in Civil 3d.

0 Likes
Message 10 of 13

shubhamraut221195
Enthusiast
Enthusiast

Ok. When I passed any one LayerStateMask as a 4th parameter to RestoreLayerState() method, it only restored the passed LayerStateMask and also chosen layer state was not assigned to current document. But then I tried adding all the LayerStateMasks then the chosen layer state was assigned to current document. Please try following block of code

ArrayList layerStates = acLyrStMan.GetLayerStateNames(false, false);
            PromptKeywordOptions opts = new PromptKeywordOptions("Select layer state");
            for(int i=0;i< layerStates.Count; i++)
            {
                opts.Keywords.Add(layerStates[i].ToString());
            }
            PromptResult result = ed.GetKeywords(opts);
            if(result.Status == PromptStatus.OK)
            {
                if (acLyrStMan.HasLayerState(result.StringResult) == true)
                {
                    acLyrStMan.RestoreLayerState(result.StringResult,
                                                 ObjectId.Null,
                                                 1,
                                                 LayerStateMasks.On | LayerStateMasks.Frozen | LayerStateMasks.Locked | LayerStateMasks.Color|LayerStateMasks.LineType|LayerStateMasks.LineWeight|LayerStateMasks.Transparency|LayerStateMasks.PlotStyle|LayerStateMasks.Plot|LayerStateMasks.NewViewport);
                }
            }

 

Message 11 of 13

swarali_kulkarni4KMYK
Alumni
Alumni

Is it really worked? assigned chosen layer state to current document? I have tried but not  assigning to current document. 

0 Likes
Message 12 of 13

shubhamraut221195
Enthusiast
Enthusiast
Accepted solution

@swarali_kulkarni4KMYK , Yes it is working. Can you tell me which way you chose to select particular layer state?

Message 13 of 13

swarali_kulkarni4KMYK
Alumni
Alumni

Yes, Its working, thank you so much for your time to find the solution.